eslint-plugin-jsdoc
JSDoc linting rules for ESLint.
Installation
Install ESLint either locally or
globally.
npm install --save-dev eslint
If you have installed ESLint
globally, you have to install JSDoc plugin
globally too. Otherwise, install it locally.
npm install --save-dev eslint-plugin-jsdoc
Configuration
Add plugins
section to .eslintrc.*
and specify eslint-plugin-jsdoc
as a plugin.
{
"plugins": [
"jsdoc"
]
}
Finally, enable all of the rules that you would like to use.
{
"rules": {
"jsdoc/check-access": 1,
"jsdoc/check-alignment": 1,
"jsdoc/check-examples": 1,
"jsdoc/check-indentation": 1,
"jsdoc/check-line-alignment": 1,
"jsdoc/check-param-names": 1,
"jsdoc/check-property-names": 1,
"jsdoc/check-syntax": 1,
"jsdoc/check-tag-names": 1,
"jsdoc/check-types": 1,
"jsdoc/check-values": 1,
"jsdoc/empty-tags": 1,
"jsdoc/implements-on-classes": 1,
"jsdoc/match-description": 1,
"jsdoc/newline-after-description": 1,
"jsdoc/no-bad-blocks": 1,
"jsdoc/no-defaults": 1,
"jsdoc/no-types": 1,
"jsdoc/no-undefined-types": 1,
"jsdoc/require-asterisk-prefix": 1,
"jsdoc/require-description": 1,
"jsdoc/require-description-complete-sentence": 1,
"jsdoc/require-example": 1,
"jsdoc/require-file-overview": 1,
"jsdoc/require-hyphen-before-param-description": 1,
"jsdoc/require-jsdoc": 1,
"jsdoc/require-param": 1,
"jsdoc/require-param-description": 1,
"jsdoc/require-param-name": 1,
"jsdoc/require-param-type": 1,
"jsdoc/require-property": 1,
"jsdoc/require-property-description": 1,
"jsdoc/require-property-name": 1,
"jsdoc/require-property-type": 1,
"jsdoc/require-returns": 1,
"jsdoc/require-returns-check": 1,
"jsdoc/require-returns-description": 1,
"jsdoc/require-returns-type": 1,
"jsdoc/require-throws": 1,
"jsdoc/require-yields": 1,
"jsdoc/require-yields-check": 1,
"jsdoc/valid-types": 1
}
}
Or you can simply add the following to .eslintrc.*,
which enables the rules commented above as "recommended":
{
"extends": ["plugin:jsdoc/recommended"]
}
You can then selectively add to or override the recommended rules.
Options
Rules may, as per the ESLint user guide, have their own individual options. In eslint-plugin-jsdoc
, a few options,
such as, exemptedBy
and contexts
, may be used across different rules.
eslint-plugin-jsdoc
options, if present, are generally in the form of an
object supplied as the second argument in an array after the error level
(any exceptions to this format are explained within that rule's docs).
{
rules: {
'jsdoc/require-example': [
'error',
{
avoidExampleOnConstructors: true,
exemptedBy: ['type']
}
]
}
}
Settings
settings.jsdoc.ignorePrivate
- Disables all rules for the comment block
on which a @private
tag (or @access private
) occurs. Defaults to
false
. Note: This has no effect with the rule check-access
(whose
purpose is to check access modifiers) or empty-tags
(which checks
@private
itself).settings.jsdoc.ignoreInternal
- Disables all rules for the comment block
on which a @internal
tag occurs. Defaults to false
. Note: This has no
effect with the rule empty-tags
(which checks @internal
itself).
maxLines
and minLines
One can use minLines
and maxLines
to indicate how many line breaks
(if any) will be checked to find a jsdoc comment block before the given
code block. These settings default to 0
and 1
respectively.
In conjunction with the require-jsdoc
rule, these settings can
be enforced so as to report problems if a jsdoc block is not found within
the specified boundaries. The settings are also used in the fixer to determine
how many line breaks to add when a block is missing.
Mode
settings.jsdoc.mode
- Set to typescript
, closure
, or jsdoc
(the
default unless the @typescript-eslint
parser is in use in which case
typescript
will be the default).
Note that if you do not wish to use separate .eslintrc.*
files for a
project containing both JavaScript and TypeScript, you can also use
overrides
. You may also
set to "permissive"
to try to be as accommodating to any of the styles,
but this is not recommended. Currently is used for the following:
check-tag-names
: Determine valid tags and aliasesno-undefined-types
: Only check @template
for types in "closure" and
"typescript" modescheck-syntax
: determines aspects that may be enforcedvalid-types
: in non-Closure mode, @extends
, @package
and access tags
(e.g., @private
) with a bracketed type are reported as are missing
names with @typedef
- For type/namepath-checking rules, determine which tags will be checked for
types/namepaths (Closure allows types on some tags which the others do not,
so these tags will additionally be checked in "closure" mode)
- For type-checking rules, impacts parsing of types (through
jsdoctypeparser
dependency); note that some TypeScript features are
not yet
supported
- Check preferred tag names
- Disallows namepath on
@interface
for "closure" mode in valid-types
(and
avoids checking in other rules)
Alias Preference
Use settings.jsdoc.tagNamePreference
to configure a preferred alias name for
a JSDoc tag. The format of the configuration is:
<primary tag name>: <preferred alias name>
, e.g.
{
"rules": {},
"settings": {
"jsdoc": {
"tagNamePreference": {
"param": "arg",
"returns": "return"
}
}
}
}
Note: ESLint does not allow settings to have keys which conflict with
Object.prototype
e.g. 'constructor'
. To work around this, you can use the
key 'tag constructor'
.
One may also use an object with a message
and replacement
.
The following will report the message
@extends is to be used over @augments as it is more evocative of classes than @augments
upon encountering @augments
.
{
"rules": {},
"settings": {
"jsdoc": {
"tagNamePreference": {
"augments": {
"message": "@extends is to be used over @augments as it is more evocative of classes than @augments",
"replacement": "extends"
}
}
}
}
}
If one wishes to reject a normally valid tag, e.g., @todo
, one may set the
tag to false
:
{
"rules": {},
"settings": {
"jsdoc": {
"tagNamePreference": {
"todo": false
}
}
}
}
A project wishing to ensure no blocks are left excluded from entering the
documentation, might wish to prevent the @ignore
tag in the above manner.
Or one may set the targeted tag to an object with a custom message
, but
without a replacement
property:
{
"rules": {},
"settings": {
"jsdoc": {
"tagNamePreference": {
"todo": {
"message": "We expect immediate perfection, so don't leave to-dos in your code."
}
}
}
}
}
Note that the preferred tags indicated in the
settings.jsdoc.tagNamePreference
map will be assumed to be defined by
check-tag-names
.
See check-tag-names
for how that fact can be used to set an alias to itself
to allow both the alias and the default (since aliases are otherwise not
permitted unless used in tagNamePreference
).
Default Preferred Aliases
The defaults in eslint-plugin-jsdoc
(for tags which offer
aliases) are as follows:
@abstract
(over @virtual
)@augments
(over @extends
)@class
(over @constructor
)@constant
(over @const
)@default
(over @defaultvalue
)@description
(over @desc
)@external
(over @host
)@file
(over @fileoverview
, @overview
)@fires
(over @emits
)@function
(over @func
, @method
)@member
(over @var
)@param
(over @arg
, @argument
)@property
(over @prop
)@returns
(over @return
)@throws
(over @exception
)@yields
(over @yield
)
This setting is utilized by the the rule for tag name checking
(check-tag-names
) as well as in the @param
and @require
rules:
check-param-names
check-tag-names
require-hyphen-before-param-description
require-description
require-param
require-param-description
require-param-name
require-param-type
require-returns
require-returns-check
require-returns-description
require-returns-type
@override
/@augments
/@extends
/@implements
Without Accompanying @param
/@description
/@example
/@returns
The following settings allows the element(s) they reference to be omitted
on the JSDoc comment block of the function or that of its parent class
for any of the "require" rules (i.e., require-param
, require-description
,
require-example
, or require-returns
).
settings.jsdoc.overrideReplacesDocs
(@override
) - Defaults to true
settings.jsdoc.augmentsExtendsReplacesDocs
(@augments
or its alias
@extends
) - Defaults to false
.settings.jsdoc.implementsReplacesDocs
(@implements
) - Defaults to false
The format of the configuration is as follows:
{
"rules": {},
"settings": {
"jsdoc": {
"overrideReplacesDocs": true,
"augmentsExtendsReplacesDocs": true,
"implementsReplacesDocs": true
}
}
}
Settings to Configure check-types
and no-undefined-types
-
settings.jsdoc.preferredTypes
An option map to indicate preferred
or forbidden types (if default types are indicated here, these will
have precedence over the default recommendations for check-types
).
The keys of this map are the types to be replaced (or forbidden).
These keys may include:
- The "ANY" type,
*
- The pseudo-type
[]
which we use to denote the parent (array)
types used in the syntax string[]
, number[]
, etc. - The pseudo-type
.<>
(or .
) to represent the format Array.<value>
or Object.<key, value>
- The pseudo-type
<>
to represent the format Array<value>
or
Object<key, value>
- A plain string type, e.g.,
MyType
- A plain string type followed by one of the above pseudo-types (except
for
[]
which is always assumed to be an Array
), e.g., Array.
, or
SpecialObject<>
.
If a bare pseudo-type is used, it will match all parent types of that form.
If a pseudo-type prefixed with a type name is used, it will only match
parent types of that form and type name.
The values can be:
false
to forbid the type- a string to indicate the type that should be preferred in its place
(and which
fix
mode can replace); this can be one of the formats
of the keys described above.
- Note that the format will not be changed unless you use a pseudo-type
in the replacement. (For example,
'Array.<>': 'MyArray'
will change
Array.<string>
to MyArray.<string>
, preserving the dot. To get rid
of the dot, you must use the pseudo-type with <>
, i.e.,
'Array.<>': 'MyArray<>'
, which will change Array.<string>
to
MyArray<string>
). - If you use a bare pseudo-type in the replacement (e.g.,
'MyArray.<>': '<>'
), the type will be converted to the format
of the pseudo-type without changing the type name. For example,
MyArray.<string>
will become MyArray<string>
but Array.<string>
will not be modified.
- an object with:
- the key
message
to provide a specific error message
when encountering the discouraged type.
- The message string will have the substrings with special meaning,
{{tagName}}
and {{tagValue}}
, replaced with their
corresponding value.
- an optional key
replacement
with either of the following values:
- a string type to be preferred in its place (and which
fix
mode
can replace) false
(for forbidding the type)
Note that the preferred types indicated as targets in
settings.jsdoc.preferredTypes
map will be assumed to be defined by
no-undefined-types
.
See the option of check-types
, unifyParentAndChildTypeChecks
, for
how the keys of preferredTypes
may have <>
or .<>
(or just .
)
appended and its bearing on whether types are checked as parents/children
only (e.g., to match Array
if the type is Array
vs. Array.<string>
).
Note that if a value is present both as a key and as a value, neither the
key nor the value will be reported. Thus in check-types
, this fact can
be used to allow both object
and Object
if one has a preferredTypes
key object: 'Object'
and Object: 'object'
.
structuredTags
An object indicating tags whose types and names/namepaths (whether defining or
referencing namepaths) will be checked, subject to configuration. If the tags
have predefined behavior or allowEmptyNamepaths
behavior, this option will
override that behavior for any specified tags, though this option can also be
used for tags without predefined behavior. Its keys are tag names and its
values are objects with the following optional properties:
name
- String set to one of the following:
"text"
- When a name is present, plain text will be allowed in the
name position (non-whitespace immediately after the tag and whitespace),
e.g., in @throws This is an error
, "This" would normally be the name,
but "text" allows non-name text here also. This is the default."namepath-defining"
- As with namepath-referencing
, but also
indicates the tag adds a namepath to definitions, e.g., to prevent
no-undefined-types
from reporting references to that namepath."namepath-referencing"
- This will cause any name position to be
checked to ensure it is a valid namepath. You might use this to ensure
that tags which normally allow free text, e.g., @see
will instead
require a namepath.false
- This will disallow any text in the name position.
type
:
true
- Allows valid types within brackets. This is the default.false
- Explicitly disallows any brackets or bracketed type. You
might use this with @throws
to suggest that only free form text
is being input or with @augments
(for jsdoc mode) to disallow
Closure-style bracketed usage along with a required namepath.- (An array of strings) - A list of permissible types.
required
- Array of one of the following (defaults to an empty array,
meaning none are required):
- One or both of the following strings (if both are included, then both
are required):
"name"
- Indicates that a name position is required (not just that
if present, it is a valid namepath). You might use this with see
to insist that a value (or namepath, depending on the name
value)
is always present."type"
- Indicates that the type position (within curly brackets)
is required (not just that if present, it is a valid type). You
might use this with @throws
or @typedef
which might otherwise
normally have their types optional. See the type groups 3-5 above.
"typeOrName"
- Must have either type (e.g., @throws {aType}
) or
name (@throws Some text
); does not require that both exist but
disallows just an empty tag.
Advanced
AST and Selectors
For various rules, one can add to the environments to which the rule applies
by using the contexts
option.
This option works with ESLint's selectors which are esquery
expressions one may use to target a specific node type or types, including
subsets of the type(s) such as nodes with certain children or attributes.
These expressions are used within ESLint plugins to find those parts of
your files' code which are of interest to check. However, in
eslint-plugin-jsdoc
, we also allow you to use these selectors to define
additional contexts where you wish our own rules to be applied.
contexts
format
While at their simplest, these can be an array of string selectors, one can
also supply an object with context
(in place of the string) and one of two
properties:
- For
require-jsdoc
, there is also a inlineCommentBlock
property. See
that rule for details. - For
no-missing-syntax
and no-restricted-syntax
, there is also a
message
property which allows customization of the message to be shown
when the rule is triggered. - For
no-missing-syntax
, there is also a minimum
property. See that rule. - For other rules, there is a
comment
property which adds to the context
in requiring that the comment
AST condition is also met, e.g., to
require that certain tags are present and/or or types and type operators
are in use. Note that this AST (either for JSDoc*
or JSDocType*
AST)
has not been standardized and should be considered experimental.
Note that this property might also become obsolete if parsers begin to
include JSDoc-structured AST. A
parser is available
which aims to support comment AST as
a first class citizen where comment/comment types can be used anywhere
within a normal AST selector but this should only be considered
experimental. When using such a parser, you need not use comment
and
can just use a plain string context. The determination of the node on
which the comment is attached is also subject to change. It may be
currently possible for different structures to map to the same comment
block. This is because normally when querying to find either the
declaration of the function expression for
const quux = function () {}
, the associated comment would,
in both cases, generally be expected to be on the line above both, rather
than to be immediately preceding the funciton (in the case of the
function). See @es-joy/jsdoccomment
for the precise structure of the comment (and comment type) nodes.
Discovering available AST definitions
To know all of the AST definitions one may target, it will depend on the
parser
you are using with ESLint (e.g., espree
is the default parser for ESLint,
and this follows EStree AST but
to support the the latest experimental features of JavaScript, one may use
@babel/eslint-parser
or to be able to have one's rules (including JSDoc rules)
apply to TypeScript, one may use @typescript-eslint/parser
, etc.
So you can look up a particular parser to see its rules, e.g., browse through
the ESTree docs as used by Espree or see
ESLint's overview of the structure of AST.
However, it can sometimes be even more helpful to get an idea of AST by just
providing some of your JavaScript to the wonderful
AST Explorer tool and see what AST is built out
of your code. You can set the tool to the specific parser which you are using.
Uses/Tips for AST
And if you wish to introspect on the AST of code within your projects, you can
use eslint-plugin-query.
Though it also works as a plugin, you can use it with its own CLI, e.g.,
to search your files for matching esquery selectors, optionally showing
it as AST JSON.
Tip: If you want to more deeply understand not just the resulting AST tree
structures for any given code but also the syntax for esquery selectors so
that you can, for example, find only those nodes with a child of a certain
type, you can set the "Transform" feature to ESLint and test out
esquery selectors in place of the selector expression (e.g., replace
'VariableDeclaration > VariableDeclarator > Identifier[name="someVar"]'
as
we have
here)
to the selector you wish so as to get messages reported in the bottom right
pane which match your esquery
selector).
Rules
check-access
Checks that @access
tags use one of the following values:
- "package", "private", "protected", "public"
Also reports:
- Mixing of
@access
with @public
, @private
, @protected
, or @package
on the same doc block. - Use of multiple instances of
@access
(or the @public
, etc. style tags)
on the same doc block.
| |
---|
Context | everywhere |
Tags | @access |
Recommended | false |
Settings | |
Options | |
The following patterns are considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
class MyClass {
myClassField = 1
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
The following patterns are not considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
class MyClass {
myClassField = 1
}
function quux (foo) {
}
function quux (foo) {
}
check-alignment
Reports invalid alignment of JSDoc block asterisks.
| |
---|
Context | everywhere |
Tags | N/A |
Recommended | true |
The following patterns are considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
class Foo {
quux(a) {}
}
The following patterns are not considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {}
function quux (foo) {
}
function quux (foo) {
}
check-examples
Ensures that (JavaScript) examples within JSDoc adhere to ESLint rules. Also
has options to lint the default values of optional @param
/@arg
/@argument
and @property
/@prop
tags or the values of @default
/@defaultvalue
tags.
Options
The options below all default to no-op/false
except as noted.
captionRequired
JSDoc specs use of an optional <caption>
element at the beginning of
@example
.
The option captionRequired
insists on a <caption>
being present at
the beginning of any @example
.
Used only for @example
.
exampleCodeRegex
and rejectExampleCodeRegex
JSDoc does not specify a formal means for delimiting code blocks within
@example
(it uses generic syntax highlighting techniques for its own
syntax highlighting). The following options determine whether a given
@example
tag will have the check-examples
checks applied to it:
exampleCodeRegex
- Regex which whitelists lintable
examples. If a parenthetical group is used, the first one will be used,
so you may wish to use (?:...)
groups where you do not wish the
first such group treated as one to include. If no parenthetical group
exists or matches, the whole matching expression will be used.
An example might be "^```(?:js|javascript)([\\s\\S]*)```\s*$"
to only match explicitly fenced JavaScript blocks. Defaults to only
using the u
flag, so to add your own flags, encapsulate your
expression as a string, but like a literal, e.g., /```js.*```/gi
.
Note that specifying a global regular expression (i.e., with g
) will
allow independent linting of matched blocks within a single @example
.rejectExampleCodeRegex
- Regex blacklist which rejects
non-lintable examples (has priority over exampleCodeRegex
). An example
might be "^`"
to avoid linting fenced blocks which may indicate
a non-JavaScript language. See exampleCodeRegex
on how to add flags
if the default u
is not sufficient.
If neither is in use, all examples will be matched. Note also that even if
captionRequired
is not set, any initial <caption>
will be stripped out
before doing the regex matching.
paddedIndent
This integer property allows one to add a fixed amount of whitespace at the
beginning of the second or later lines of the example to be stripped so as
to avoid linting issues with the decorative whitespace. For example, if set
to a value of 4
, the initial whitespace below will not trigger indent
rule errors as the extra 4 spaces on each subsequent line will be stripped
out before evaluation.
Only applied to @example
linting.
reportUnusedDisableDirectives
If not set to false
, reportUnusedDisableDirectives
will report disabled
directives which are not used (and thus not needed). Defaults to true
.
Corresponds to ESLint's --report-unused-disable-directives
.
Inline ESLint config within @example
JavaScript is allowed (or within
@default
, etc.), though the disabling of ESLint directives which are not
needed by the resolved rules will be reported as with the ESLint
--report-unused-disable-directives
command.
Options for Determining ESLint Rule Applicability (allowInlineConfig
, noDefaultExampleRules
, matchingFileName
, configFile
, checkEslintrc
, and baseConfig
)
The following options determine which individual ESLint rules will be
applied to the JavaScript found within the @example
tags (as determined
to be applicable by the above regex options) or for the other tags checked by
checkDefaults
, checkParams
, or checkProperties
options. They are ordered
by decreasing precedence:
allowInlineConfig
- If not set to false
, will allow
inline config within the @example
to override other config. Defaults
to true
.noDefaultExampleRules
- Setting to true
will disable the
default rules which are expected to be troublesome for most documentation
use. See the section below for the specific default rules.configFile
- A config file. Corresponds to ESLint's -c
.matchingFileName
- Option for a file name (even non-existent) to trigger
specific rules defined in one's config; usable with ESLint .eslintrc.*
overrides
-> files
globs, to apply a desired subset of rules with
@example
(besides allowing for rules specific to examples, this option
can be useful for enabling reuse of the same rules within @example
as
with JavaScript Markdown lintable by
other plugins, e.g.,
if one sets matchingFileName
to dummy.md/*.js
so that @example
rules will follow rules for fenced JavaScript blocks within one's Markdown
rules). (In ESLint 6's processor API and eslint-plugin-markdown
< 2, one
would instead use dummy.md
.) For @example
only.matchingFileNameDefaults
- As with matchingFileName
but for use with
checkDefaults
and defaulting to .jsdoc-defaults
as extension.matchingFileNameParams
- As with matchingFileName
but for use with
checkParams
and defaulting to .jsdoc-params
as extension.matchingFileNameProperties
As with matchingFileName
but for use with
checkProperties
and defaulting to .jsdoc-properties
as extension.checkEslintrc
- Defaults to true
in adding rules
based on an .eslintrc.*
file. Setting to false
corresponds to
ESLint's --no-eslintrc
.
If matchingFileName
is set, this will automatically be true
and
will use the config corresponding to that file. If matchingFileName
is
not set and this value is set to false
, the .eslintrc.*
configs will
not be checked. If matchingFileName
is not set, and this is unset or
set to true
, the .eslintrc.*
configs will be checked as though the file
name were the same as the file containing the example, with any file
extension changed to ".md/*.js"
(and if there is no file extension,
"dummy.md/*.js"
will be the result). This allows convenient sharing of
similar rules with often also context-free Markdown as well as use of
overrides
as described under matchingFileName
. Note that this option
(whether set by matchingFileName
or set manually to true
) may come at
somewhat of a performance penalty as the file's existence is checked by
eslint.baseConfig
- Set to an object of rules with the same schema
as .eslintrc.*
for defaults.
Rules Disabled by Default Unless noDefaultExampleRules
is Set to true
eol-last
- Insisting that a newline "always" be at the end is less likely
to be desired in sample code as with the code file convention.no-console
- This rule is unlikely to have inadvertent temporary debugging
within examples.no-multiple-empty-lines
- This rule may be problematic for projects which
use an initial newline just to start an example. Also, projects may wish to
use extra lines within examples just for easier illustration
purposes.no-undef
- Many variables in examples will be undefined
.no-unused-vars
- It is common to define variables for clarity without
always using them within examples.padded-blocks
- It can generally look nicer to pad a little even if one's
code follows more stringency as far as block padding.jsdoc/require-file-overview
- Shouldn't check example for jsdoc blocks.jsdoc/require-jsdoc
- Wouldn't expect jsdoc blocks within jsdoc blocks.import/no-unresolved
- One wouldn't generally expect example paths to
resolve relative to the current JavaScript file as one would with real code.import/unambiguous
- Snippets in examples are likely too short to always
include full import/export info.node/no-missing-import
- See import/no-unresolved
.node/no-missing-require
- See import/no-unresolved
.
For checkDefaults
, checkParams
, and checkProperties
, the following
expression-oriented rules will be used by default as well:
quotes
- Will insist on "double".semi
- Will insist on "never"strict
- Disabled.no-new
- Disabled.no-unused-expressions
- Disabled.
Options for checking other than @example
(checkDefaults
, checkParams
, or checkProperties
)
checkDefaults
- Whether to check the values of @default
/@defaultvalue
tagscheckParams
- Whether to check @param
/@arg
/@argument
default valuescheckProperties
- Whether to check @property
/@prop
default values
| |
---|
Context | everywhere |
Tags | example |
Recommended | false |
Options | See above |
The following patterns are considered problems:
function quux () {
}
class quux {
}
function quux () {
}
function quux () {
}
var quux = {
};
function quux () {
}
function quux () {
}
function quux2 () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {}
function quux () {}
function quux2 () {
}
function quux2 () {
}
function quux2 () {
}
function quux2 () {
}
function quux2 () {
}
function quux2 () {
}
function quux2 () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
const str = 'abc';
function quux () {
}
const obj = {};
const functionName = function (paramOne, paramTwo,
paramThree) {
return false;
};
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {}
function quux () {}
var quux = {
};
function quux () {}
function quux () {
}
function quux2 () {
}
function quux () {
}
a();
export default {};
function f () {
}
function quux () {
}
const str = 'abc';
const str = 'abc';
function quux () {
}
function quux () {
}
const obj = {};
const obj = {};
const str = 'abc';
function quux () {
}
const obj = {};
const functionName = function (paramOne, paramTwo,
paramThree) {
return false;
};
check-indentation
Reports invalid padding inside JSDoc blocks.
Ignores parts enclosed in Markdown "code block"'s. For example,
the following description is not reported:
Options
This rule has an object option.
excludeTags
Array of tags (e.g., ['example', 'description']
) whose content will be
"hidden" from the check-indentation
rule. Defaults to ['example']
.
By default, the whole JSDoc block will be checked for invalid padding.
That would include @example
blocks too, which can get in the way
of adding full, readable examples of code without ending up with multiple
linting issues.
When disabled (by passing excludeTags: []
option), the following code will
report a padding issue:
| |
---|
Context | everywhere |
Tags | N/A |
Recommended | false |
Options | excludeTags |
The following patterns are considered problems:
function quux () {
}
function quux () {
}
class Moo {}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
check-line-alignment
Reports invalid alignment of JSDoc block lines. This is a
standard recommended to WordPress code,
for example.
Options
This rule allows one optional string argument. If it is "always"
then a
problem is raised when the lines are not aligned. If it is "never"
then
a problem should be raised when there is more than one space between each
line's parts. Defaults to "never"
.
Note that in addition to alignment, both options will ensure at least one
space is present after the asterisk delimiter.
After the string, an options object is allowed with the following properties.
tags
Use this to change the tags which are sought for alignment changes. Currently
only works with the "never" option. Defaults to an array of
['param', 'arg', 'argument', 'property', 'prop', 'returns', 'return']
.
customSpacings
An object with any of the following keys set to an integer. Affects spacing:
postDelimiter
- after the asterisk (e.g., * @param
)postTag
- after the tag (e.g., * @param
)postType
- after the type (e.g., * @param {someType}
)postName
- after the name (e.g., * @param {someType} name
)
If a spacing is not defined, it defaults to one.
| |
---|
Context | everywhere |
Options | (a string matching "always" or "never" and optional object with tags and customSpacings ) |
Tags | param , property , returns and others added by tags |
Aliases | arg , argument , prop , return |
Recommended | false |
The following patterns are considered problems:
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
function fn( lorem, sit ) {}
const object = {
fn( lorem, sit ) {}
}
class ClassName {
fn( lorem, sit ) {}
}
const fn = ( lorem, sit ) => {}
const config = {
defaults: {
lorem: 1
}
}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
function quux () {}
function quux () {}
function quux () {}
function quux () {}
function quux () {}
function quux () {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
The following patterns are not considered problems:
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = () => {}
const fn = ( lorem, sit ) => {}
function fn( lorem, sit ) {}
const object = {
fn( lorem, sit ) {},
}
class ClassName {
fn( lorem, sit ) {}
}
const fn = ( lorem, sit ) => {}
const config = {
defaults: {
lorem: 1
}
}
const fn = ( lorem ) => {}
function quux () {}
function quux () {}
function quux () {}
const fn = ( lorem, sit ) => {}
function quux (options) {}
function quux () {}
function func(parameter){
}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
const fn = ({ids}) => {}
check-param-names
Ensures that parameter names in JSDoc match those in the function declaration.
Destructuring
Note that by default the rule will not report parameters present on the docs
but non-existing on the function signature when an object rest property is part
of that function signature since the seemingly non-existing properties might
actually be a part of the object rest property.
function quux ({foo, ...extra}) {}
To require that extra
be documented--and that any extraneous properties
get reported--e.g., if there had been a @param options.bar
above--you
can use the checkRestProperty
option which insists that the rest
property be documented (and that there be no other implicit properties).
Note, however, that jsdoc does not appear
to currently support syntax or output to distinguish rest properties from
other properties, so in looking at the docs alone without looking at the
function signature, the disadvantage of enabling this option is that it
may appear that there is an actual property named extra
.
Options
checkRestProperty
See the "Destructuring" section. Defaults to false
.
checkTypesPattern
See require-param
under the option of the same name.
enableFixer
Set to true
to auto-remove @param
duplicates (based on identical
names).
Note that this option will remove duplicates of the same name even if
the definitions do not match in other ways (e.g., the second param will
be removed even if it has a different type or description).
If set to true
, this option will allow extra @param
definitions (e.g.,
representing future expected or virtual params) to be present without needing
their presence within the function signature. Other inconsistencies between
@param
's and present function parameters will still be reported.
checkDestructured
Whether to check destructured properties. Defaults to true
.
useDefaultObjectProperties
Set to true
if you wish to avoid reporting of child property documentation
where instead of destructuring, a whole plain object is supplied as default
value but you wish its keys to be considered as signalling that the properties
are present and can therefore be documented. Defaults to false
.
Whether to check for extra destructured properties. Defaults to false
. Change
to true
if you want to be able to document properties which are not actually
destructured. Keep as false
if you expect properties to be documented in
their own types. Note that extra properties will always be reported if another
item at the same level is destructured as destructuring will prevent other
access and this option is only intended to permit documenting extra properties
that are available and actually used in the function.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression |
Options | allowExtraTrailingParamDocs , checkDestructured , checkRestProperty , checkTypesPattern , useDefaultObjectProperties , disableExtraPropertyReporting |
Tags | param |
Aliases | arg , argument |
Recommended | true |
The following patterns are considered problems: | |
function quux (foo = 'FOO') {
}
function quux (foo = 'FOO') {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function assign (employees) {
};
function assign (employees) {
};
function quux (bar, foo) {
}
function quux (foo) {
}
function quux (foo) {
}
class bar {
quux (foo) {
}
}
function quux (foo, bar) {
}
function quux (foo, foo) {
}
function quux ({foo}) {
}
function quux ({foo}) {
}
function quux ({foo, bar}) {
}
function quux ({foo}, baz) {
}
function quux ({foo, bar}, baz) {
}
function quux ({foo}, baz) {
}
function quux ({foo, bar}, baz) {
}
function quux ({a, b}) {
}
function quux ({a, b} = {}) {
}
export class SomeClass {
constructor(private property: string) {}
}
export class SomeClass {
constructor(prop: { foo: string, bar: string }) {}
}
export class SomeClass {
constructor(options: { foo: string, bar: string }) {}
}
export class SomeClass {
constructor(options: { foo: string }) {}
}
function quux (foo) {
}
function quux (error, cde = 1) {
};
function quux ([a, b] = []) {
}
function quux ({foo, ...extra}) {
}
function quux ({foo, ...extra}) {
}
const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
module.exports = class GraphQL {
fetch = ({ url, ...options }, cacheKey) => {
}
};
function testingEslint(options: {
one: string;
two: string;
three: string;
}): string {
return one + two + three;
}
function quux() {
}
function quux ({foo, bar}, baz) {
}
function quux ({ foo: { bar } }) {}
function quux ({ foo: { bar } }) {}
function foo({ foo: { bar: { baz } }}) {}
export function testFn1 ({ prop = { a: 1, b: 2 } }) {
}
function quux ({foo}) {
}
function quux ({foo}) {
}
function quux ({cfg: {a: {foo}}}) {
}
function quux ({cfg: {a: {foo}}}) {
}
function quux ({cfg}) {
}
function quux (foo) {
}
The following patterns are not considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo, bar) {
}
function quux (foo, bar, baz) {
}
function quux (foo, bar) {
}
function quux (...args) {
}
function quux ({a, b}) {
}
function quux ({"a": A, b}) {
}
function quux ({a: A, b}) {
}
function quux ({"a-b": A, b}) {
}
function quux (foo, bar) {
}
function assign (employees) {
};
export class SomeClass {
constructor(private property: string) {}
}
export class SomeClass {
constructor(options: { foo: string, bar: string }) {}
}
export class SomeClass {
constructor({ foo, bar }: { foo: string, bar: string }) {}
}
export class SomeClass {
constructor({ foo, bar }: { foo: string, bar: string }) {}
}
function quux (error, code = 1) {
};
function quux (foo) {
}
function quux ({foo}, baz) {
}
function quux ({foo}, cfg2) {
}
function quux ({foo}, {cfg}) {
}
function quux ({foo, ...extra}) {
}
function quux (foo, bar, ...extra) {
}
const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
class CSS {
setCssObject(propertyObject: {[key: string]: string | number}): void {
}
}
export default function (input: {
[foo: string]: { a: string; b: string };
}): void {
input;
}
export class Thing {
foo: any;
constructor(C: { new (): any }) {
this.foo = new C();
}
}
function quux (foo, {bar}) {
}
class A {
public async showPrompt(hideButton: boolean, onHidden: {(): void}): Promise<void>
{
}
}
function quux ({ foo: { bar }}) {}
function quux ({ foo: { bar } }) {}
function quux ({ foo: { bar }, baz: { cfg } }) {}
export default function Item({
data: {
className,
} = {},
val = 4
}) {
}
function Item({
data: [foo, bar, ...baz],
defaulting: [quux, xyz] = []
}) {
}
export function testFn1 ({ prop = { a: 1, b: 2 } }) {
}
function quux ({cfg}) {
}
class A {
constructor({
[new.target.prop]: cX,
abc
}) {
}
}
const foo = ([, b]) => b;
check-property-names
Ensures that property names in JSDoc are not duplicated on the same block
and that nested properties have defined roots.
Options
enableFixer
Set to true
to auto-remove @property
duplicates (based on
identical names).
Note that this option will remove duplicates of the same name even if
the definitions do not match in other ways (e.g., the second property will
be removed even if it has a different type or description).
| |
---|
Context | Everywhere |
Options | enableFixer |
Tags | property |
Aliases | prop |
Recommended | true |
The following patterns are considered problems:
function quux ({foo, bar}) {
}
class Test {
quux ({foo, bar}) {
}
}
function quux ({foo, bar}, baz) {
}
function quux ({foo, bar}, baz) {
}
The following patterns are not considered problems:
function quux (code = 1) {
this.error = new Error('oops');
this.code = code;
}
check-syntax
Reports against syntax not encouraged for the mode (e.g., Google Closure
Compiler in "jsdoc" or "typescript" mode). Note that this rule will not check
for types that are wholly invalid for a given mode, as that is covered by
valid-types
.
Currently checks against:
- Use of
=
in "jsdoc" or "typescript" mode
Note that "jsdoc" actually allows Closure syntax, but with another
option available for optional parameters (enclosing the name in brackets), the
rule is enforced (except under "permissive" and "closure" modes).
| |
---|
Context | everywhere |
Tags | N/A |
Recommended | false |
The following patterns are considered problems:
function quux (foo) {
}
The following patterns are not considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
check-tag-names
Reports invalid block tag names.
Valid JSDoc 3 Block Tags are:
abstract
access
alias
async
augments
author
borrows
callback
class
classdesc
constant
constructs
copyright
default
deprecated
description
enum
event
example
exports
external
file
fires
function
generator
global
hideconstructor
ignore
implements
inheritdoc
inner
instance
interface
kind
lends
license
listens
member
memberof
memberof!
mixes
mixin
module
name
namespace
override
package
param
private
property
protected
public
readonly
requires
returns
see
since
static
summary
this
throws
todo
tutorial
type
typedef
variation
version
yields
modifies
is also supported (see source)
but is undocumented.
The following synonyms are also recognized if you set them in
tagNamePreference
as a key (or replacement):
arg
argument
const
constructor
defaultvalue
desc
emits
exception
extends
fileoverview
func
host
method
overview
prop
return
var
virtual
yield
If you wish to allow in certain cases both a primary tag name and its
alias(es), you can set a normally non-preferred tag name to itself to indicate
that you want to allow both the default tag (in this case @returns
) and a
non-default (in this case return
):
"tagNamePreference": {
"return": "return",
}
Because the tags indicated as replacements in
settings.jsdoc.tagNamePreference
will automatically be considered as valid,
the above works.
Likewise are the tag keys of settings.jsdoc.structuredTags
automatically
considered as valid (as their defining an expected structure for tags implies
the tags may be used).
For TypeScript
(or Closure), when settings.jsdoc.mode
is set to typescript
or closure
,
one may also use the following:
template
And for Closure,
when settings.jsdoc.mode
is set to closure
, one may use the following (in
addition to the jsdoc and TypeScript tags–though replacing returns
with
return
):
define (synonym of `const` per jsdoc source)
dict
export
externs
final
implicitCast (casing distinct from that recognized by jsdoc internally)
inheritDoc (casing distinct from that recognized by jsdoc internally)
noalias
nocollapse
nocompile
noinline
nosideeffects
polymer
polymerBehavior
preserve
record (synonym of `interface` per jsdoc source)
struct
suppress
unrestricted
...and these undocumented tags which are only in source:
closurePrimitive
customElement
expose
hidden
idGenerator
meaning
mixinClass
mixinFunction
ngInject
owner
typeSummary
wizaction
Options
definedTags
Use an array of definedTags
strings to configure additional, allowed tags.
The format is as follows:
{
"definedTags": ["note", "record"]
}
jsxTags
If this is set to true
, all of the following tags used to control JSX output are allowed:
jsx
jsxFrag
jsxImportSource
jsxRuntime
For more information, see the babel documentation.
| |
---|
Context | everywhere |
Tags | N/A |
Recommended | true |
Options | definedTags |
Settings | tagNamePreference , mode |
The following patterns are considered problems:
let a;
let a;
function quux () {
}
function quux () {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux (foo) {}
function quux (foo) {}
function quux (foo) {}
function quux (foo) {}
The following patterns are not considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {}
function quux (foo) {}
function quux (foo) {}
function quux (foo) {}
function quux (foo) {}
function quux (foo) {
}
function quux () {
}
function quux () {
}
function quux () {
}
export function transient<T>(target?: T): T {
}
check-types
Reports invalid types.
By default, ensures that the casing of native types is the same as in this
list:
undefined
null
boolean
number
bigint
string
symbol
object
Array
Function
Date
RegExp
Options
check-types
allows one option:
- An option object:
- with the key
noDefaults
to insist that only the supplied option type
map is to be used, and that the default preferences (such as "string"
over "String") will not be enforced. The option's default is false
. - with the key
exemptTagContexts
which will avoid reporting when a
bad type is found on a specified tag. Set to an array of objects with
a key tag
set to the tag to exempt, and a types
key which can
either be true
to indicate that any types on that tag will be allowed,
or to an array of strings which will only allow specific bad types.
If an array of strings is given, these must match the type exactly,
e.g., if you only allow "object"
, it will not allow
"object<string, string>"
. Note that this is different from the
behavior of settings.jsdoc.preferredTypes
. This option is useful
for normally restricting generic types like object
with
preferredTypes
, but allowing typedef
to indicate that its base
type is object
. - with the key
unifyParentAndChildTypeChecks
which will treat
settings.jsdoc.preferredTypes
keys such as SomeType
as matching
not only child types such as an unadorned SomeType
but also
SomeType<aChildType>
, SomeType.<aChildType>
, or if SomeType
is
Array
(or []
), it will match aChildType[]
. If this is false
or
unset, the former format will only apply to types which are not parent
types/unions whereas the latter formats will only apply for parent
types/unions. The special types []
, .<>
(or .
), and <>
act only as parent types (and will not match a bare child type such as
Array
even when unified, though, as mentioned, Array
will match
say string[]
or Array.<string>
when unified). The special type
*
is only a child type. Note that there is no detection of parent
and child type together, e.g., you cannot specify preferences for
string[]
specifically as distinct from say number[]
, but you can
target both with []
or the child types number
or string
.
If a value is present both as a key and as a value, neither the key nor the
value will be reported. Thus one can use this fact to allow both object
and Object
, for example. Note that in "typescript" mode, this is the default
behavior.
See also the documentation on settings.jsdoc.preferredTypes
which impacts
the behavior of check-types
.
Note that if there is an error parsing
types for a tag, the function will silently ignore that tag, leaving it to
the valid-types
rule to report parsing errors.
Why not capital case everything?
Why are boolean
, number
and string
exempt from starting with a capital
letter? Let's take string
as an example. In Javascript, everything is an
object. The string Object has prototypes for string functions such as
.toUpperCase()
.
Fortunately we don't have to write new String()
everywhere in our code.
Javascript will automatically wrap string primitives into string Objects when
we're applying a string function to a string primitive. This way the memory
footprint is a tiny little bit smaller, and the
GC has
less work to do.
So in a sense, there two types of strings in Javascript; {string}
literals,
also called primitives and {String}
Objects. We use the primitives because
it's easier to write and uses less memory. {String}
and {string}
are
technically both valid, but they are not the same.
new String('lard')
'lard'
new String('lard') === 'lard'
To make things more confusing, there are also object literals and object
Objects. But object literals are still static Objects and object Objects are
instantiated Objects. So an object primitive is still an object Object.
However, Object.create(null)
objects are not instanceof Object
, however, so
in the case of this Object we lower-case to indicate possible support for
these objects.
Basically, for primitives, we want to define the type as a primitive, because
that's what we use in 99.9% of cases. For everything else, we use the type
rather than the primitive. Otherwise it would all just be {object}
.
In short: It's not about consistency, rather about the 99.9% use case. (And
some functions might not even support the objects if they are checking for
identity.)
type name | typeof | check-types | testcase |
---|
Array | object | Array | ([]) instanceof Array -> true |
Function | function | Function | (function f () {}) instanceof Function -> true |
Date | object | Date | (new Date()) instanceof Date -> true |
RegExp | object | RegExp | (new RegExp(/.+/)) instanceof RegExp -> true |
Object | object | object | ({}) instanceof Object -> true but Object.create(null) instanceof Object -> false |
Boolean | boolean | boolean | (true) instanceof Boolean -> false |
Number | number | number | (41) instanceof Number -> false |
String | string | string | ("test") instanceof String -> false |
If you define your own tags and don't wish their bracketed portions checked
for types, you can use settings.jsdoc.structuredTags
with a tag type
of
false
. If you set their type
to an array, only those values will be
permitted.
| |
---|
Context | everywhere |
Tags | augments , class , constant , enum , implements , member , module , namespace , param , property , returns , throws , type , typedef , yields |
Aliases | constructor , const , extends , var , arg , argument , prop , return , exception , yield |
Closure-only | package , private , protected , public , static |
Recommended | true |
Options | noDefaults , exemptTagContexts , unifyParentAndChildTypeChecks |
Settings | preferredTypes , mode , structuredTags |
The following patterns are considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux () {
}
function quux (foo, bar, baz) {
}
function quux (foo, bar, baz) {
}
function quux (foo, bar, baz) {
}
function qux(foo) {
}
function qux(foo) {
}
function qux(foo) {
}
function qux(foo, bar, baz) {
}
function qux(foo) {
}
function qux(foo) {
}
function qux(foo, bar) {
}
function qux(foo, bar) {
}
function qux(foo) {
}
function qux(foo) {
}
function qux(baz) {
}
function qux(baz) {
}
function qux(foo, bar) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux () {}
function quux () {}
function quux (foo) {
}
function a () {}
function b () {}
The following patterns are not considered problems:
function quux (foo, bar, baz) {
}
function quux (foo, bar, baz) {
}
function quux (foo, bar, baz) {
}
function qux(foo) {
}
function qux(foo) {
}
function qux(foo) {
}
function qux(foo) {
}
function quux () {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
var subscribe = function(callback) {};
function quux () {}
function quux () {}
function a () {}
function b () {}
function a () {}
function b () {}
check-values
This rule checks the values for a handful of tags:
@version
- Checks that there is a present and valid
semver version value.@since
- As with @version
@license
- Checks that there is a present and valid SPDX identifier
or is present within an allowedLicenses
option.@author
- Checks that there is a value present, and if the option
allowedAuthors
is present, ensure that the author value is one
of these array items.@variation
- If numericOnlyVariation
is set, will checks that there
is a value present, and that it is an integer (otherwise, jsdoc allows any
value).
Options
allowedAuthors
An array of allowable author values. If absent, only non-whitespace will
be checked for.
allowedLicenses
An array of allowable license values or true
to allow any license text.
If present as an array, will be used in place of SPDX identifiers.
licensePattern
A string to be converted into a RegExp
(with u
flag) and whose first
parenthetical grouping, if present, will match the portion of the license
description to check (if no grouping is present, then the whole portion
matched will be used). Defaults to /([^\n]*)/gu
, i.e., the SPDX expression
is expected before any line breaks.
Note that the /
delimiters are optional, but necessary to add flags.
Defaults to using the u
flag, so to add your own flags, encapsulate
your expression as a string, but like a literal, e.g., /^mit$/ui
.
numericOnlyVariation
Whether to enable validation that @variation
must be a number. Defaults to
false
.
| |
---|
Context | everywhere |
Tags | @version , @since , @license , @author , @variation |
Recommended | true |
Options | allowedAuthors , allowedLicenses , licensePattern |
Settings | tagNamePreference |
The following patterns are considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
Some extra text"; expected SPDX expression: https://spdx.org/licenses/.
/**
* @author
*/
function quux (foo) {
}
// Message: Missing JSDoc @author value.
/**
* @author Brett Zamir
*/
function quux (foo) {
}
// "jsdoc/check-values": ["error"|"warn", {"allowedAuthors":["Gajus Kuizinas","golopot"]}]
// Message: Invalid JSDoc @author: "Brett Zamir"; expected one of Gajus Kuizinas, golopot.
/**
* @variation
*/
function quux (foo) {
}
// "jsdoc/check-values": ["error"|"warn", {"numericOnlyVariation":true}]
// Message: Missing JSDoc @variation value.
/**
* @variation 5.2
*/
function quux (foo) {
}
// "jsdoc/check-values": ["error"|"warn", {"numericOnlyVariation":true}]
// Message: Invalid JSDoc @variation: "5.2".
The following patterns are not considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
empty-tags
Expects the following tags to be empty of any content:
@abstract
@async
@generator
@global
@hideconstructor
@ignore
@inheritdoc
@inner
@instance
@internal
(used by TypeScript)@override
@readonly
The following will also be expected to be empty unless settings.jsdoc.mode
is set to "closure" (which allows types).
@package
@private
@protected
@public
@static
Note that @private
will still be checked for content by this rule even with
settings.jsdoc.ignorePrivate
set to true
(a setting which normally
causes rules not to take effect).
Similarly, @internal
will still be checked for content by this rule even with
settings.jsdoc.ignoreInternal
set to true
.
Options
tags
If you want additional tags to be checked for their descriptions, you may
add them within this option.
{
'jsdoc/empty-tags': ['error', {tags: ['event']}]
}
| |
---|
Context | everywhere |
Tags | abstract , async , generator , global , hideconstructor , ignore , inheritdoc , inner , instance , internal , override , readonly , package , private , protected , public , static and others added by tags |
Recommended | true |
Options | tags |
The following patterns are considered problems: | |
function quux () {
}
class Test {
quux () {
}
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {}
implements-on-classes
Reports an issue with any non-constructor function using @implements
.
Constructor functions, whether marked with @class
, @constructs
, or being
an ES6 class constructor, will not be flagged.
To indicate that a function follows another function's signature, one might
instead use @type
to indicate the @function
or @callback
to which the
function is adhering.
Options
contexts
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to "any"
if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
expression, i.e., @callback
or @function
(or its aliases @func
or
@method
) (including those associated with an @interface
).
See the "AST and Selectors"
section of our README for more on the expected format.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | implements (prevented) |
Recommended | true |
Options | contexts |
The following patterns are considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
class Foo {
constructor() {}
bar() {}
}
class Foo {
constructor() {}
bar() {}
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
class quux {
constructor () {
}
}
const quux = class {
constructor () {
}
}
function quux () {
}
function quux () {
}
match-description
Enforces a regular expression pattern on descriptions.
The default is this basic expression to match English sentences (Support
for Unicode upper case may be added in a future version when it can be handled
by our supported Node versions):
^([A-Z]|[`\\d_])[\\s\\S]*[.?!`]$
Applies to the jsdoc block description and @description
(or @desc
)
by default but the tags
option (see below) may be used to match other tags.
The default (and all regex options) defaults to using (only) the u
flag, so
to add your own flags, encapsulate your expression as a string, but like a
literal, e.g., /[A-Z].*\\./ui
.
Note that /
delimiters are optional, but necessary to add flags (besides
u
).
Also note that the default or optional regular expressions is not
case-insensitive unless one opts in to add the i
flag.
You can add the s
flag if you want .
to match newlines. Note, however,
that the trailing newlines of a description will not be matched.
Options
matchDescription
You can supply your own expression to override the default, passing a
matchDescription
string on the options object.
{
'jsdoc/match-description': ['error', {matchDescription: '[A-Z].*\\.'}]
}
tags
If you want different regular expressions to apply to tags, you may use
the tags
option object:
{
'jsdoc/match-description': ['error', {tags: {
param: '\\- [A-Z].*\\.',
returns: '[A-Z].*\\.'
}}]
}
In place of a string, you can also add true
to indicate that a particular
tag should be linted with the matchDescription
value (or the default).
{
'jsdoc/match-description': ['error', {tags: {
param: true,
returns: true
}}]
}
The tags @param
/@arg
/@argument
and @property
/@prop
will be properly
parsed to ensure that the matched "description" text includes only the text
after the name.
All other tags will treat the text following the tag name, a space, and
an optional curly-bracketed type expression (and another space) as part of
its "description" (e.g., for @returns {someType} some description
, the
description is some description
while for @some-tag xyz
, the description
is xyz
).
mainDescription
If you wish to override the main function description without changing the
default match-description
, you may use mainDescription
:
{
'jsdoc/match-description': ['error', {
mainDescription: '[A-Z].*\\.',
tags: {
param: true,
returns: true
}
}]
}
There is no need to add mainDescription: true
, as by default, the main
function (and only the main function) is linted, though you may disable
checking it by setting it to false
.
contexts
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
(e.g., ClassDeclaration
for ES6
classes). Overrides the default contexts (see below). Set to "any"
if you
want the rule to apply to any jsdoc block throughout your files.
See the "AST and Selectors"
section of our README for more on the expected format.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | docblock and @description by default but more with tags |
Aliases | @desc |
Recommended | false |
Settings | |
Options | contexts , tags (accepts tags with names and optional type such as 'param', 'arg', 'argument', 'property', and 'prop', and accepts arbitrary list of other tags with an optional type (but without names), e.g., 'returns', 'return'), mainDescription , matchDescription |
The following patterns are considered problems:
const q = class {
}
const q = {
};
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function longDescription (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux () {
}
function quux () {
}
class quux {
}
class MyClass {
myClassField = 1
}
interface quux {
}
const myObject = {
myProp: true
};
function quux (foo) {
}
function quux (foo) {
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
class quux {
}
class quux {
}
class MyClass {
myClassField = 1
}
interface quux {
}
const myObject = {
myProp: true
};
const q = class {
}
const q = {
};
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux (foo) {
}
function quux (foo) {
}
function quux () {
}
function quux (foo) {
}
multiline-blocks
Controls how and whether jsdoc blocks can be expressed as single or multiple
line blocks.
Note that if you set noSingleLineBlocks
and noMultilineBlocks
to true
and configure them in a certain manner, you might effectively be prohibiting
all jsdoc blocks!
Also allows for preventing text at the very beginning or very end of blocks.
Options
A single options object with the following properties.
noZeroLineText
(defaults to true
)
For multiline blocks, any non-whitespace text immediately after the /**
and
space will be reported. (Text after a newline is not reported.)
noMultilineBlocks
will have priority over this rule if it applies.
noFinalLineText
(defaults to true
)
For multiline blocks, any non-whitespace text preceding the */
on the final
line will be reported. (Text preceding a newline is not reported.)
noMultilineBlocks
will have priority over this rule if it applies.
noSingleLineBlocks
(defaults to false
)
If this is true
, any single line blocks will be reported, except those which
are whitelisted in singleLineTags
.
singleLineTags
(defaults to ['lends', 'type']
)
An array of tags which can nevertheless be allowed as single line blocks when
noSingleLineBlocks
is set. You may set this to a empty array to
cause all single line blocks to be reported. If '*'
is present, then
the presence of a tag will allow single line blocks (but not if a tag is
missing).
noMultilineBlocks
(defaults to false
)
Requires that jsdoc blocks are restricted to single lines only unless impacted
by the options minimumLengthForMultiline
, multilineTags
, or
allowMultipleTags
.
minimumLengthForMultiline
(defaults to not being in effect)
If noMultilineBlocks
is set with this numeric option, multiline blocks will
be permitted if containing at least the given amount of text.
If not set, multiline blocks will not be permitted regardless of length unless
a relevant tag is present and multilineTags
is set.
multilineTags
(defaults to ['*']
)
If noMultilineBlocks
is set with this option, multiline blocks may be allowed
regardless of length as long as a tag or a tag of a certain type is present.
If *
is included in the array, the presence of a tags will allow for
multiline blocks (but not when without any tags unless the amount of text is
over an amount specified by minimumLengthForMultiline
).
If the array does not include *
but lists certain tags, the presence of
such a tag will cause multiline blocks to be allowed.
You may set this to an empty array to prevent any tag from permitting multiple
lines.
allowMultipleTags
(defaults to true
)
If noMultilineBlocks
is set to true
with this option and multiple tags are
found in a block, an error will not be reported.
Since multiple-tagged lines cannot be collapsed into a single line, this option
prevents them from being reported. Set to false
if you really want to report
any blocks.
This option will also be applied when there is a block description and a single
tag (since a description cannot precede a tag on a single line, and also
cannot be reliably added after the tag either).
| |
---|
Context | everywhere |
Tags | Any (though singleLineTags and multilineTags control the application) |
Recommended | true |
Settings | |
Options | noZeroLineText , noSingleLineBlocks , singleLineTags , noMultilineBlocks , minimumLengthForMultiline , multilineTags , allowMultipleTags , noFinalLineText |
The following patterns are considered problems:
The following patterns are not considered problems:
newline-after-description
Enforces a consistent padding of the block description.
Options
This rule allows one optional string argument. If it is "always"
then a
problem is raised when there is no newline after the description. If it is
"never"
then a problem is raised when there is a newline after the
description. The default value is "always"
.
| |
---|
Context | everywhere |
Tags | N/A (doc block) |
Options | (a string matching "always" or "never" ) |
Recommended | true |
The following patterns are considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function example() {
return 42;
}
function example() {
return 42;
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
export function parseQueryString(queryString: string): { [key: string]: string } {
}
function example() {
return 42;
}
function example() {
return 42;
}
no-bad-blocks
This rule checks for multi-line-style comments which fail to meet the
criteria of a jsdoc block, namely that it should begin with two and only two
asterisks, but which appear to be intended as jsdoc blocks due to the presence
of whitespace followed by whitespace or asterisks, and
an at-sign (@
) and some non-whitespace (as with a jsdoc block tag).
Options
Takes an optional options object with the following.
ignore
An array of directives that will not be reported if present at the beginning of
a multi-comment block and at-sign /* @
.
Defaults to ['ts-check', 'ts-expect-error', 'ts-ignore', 'ts-nocheck']
(some directives used by TypeScript).
preventAllMultiAsteriskBlocks
A boolean (defaulting to false
) which if true
will prevent all
multi-asterisked blocks even those without apparent tag content.
| |
---|
Context | Everywhere |
Tags | N/A |
Recommended | false |
Options | ignore , preventAllMultiAsteriskBlocks |
The following patterns are considered problems:
function quux (foo) {
}
function quux() {
}
function echo() {
return 'Something';
}
function quux (foo) {
}
function quux (foo) {
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux (foo) {
}
no-defaults
This rule reports defaults being used on the relevant portion of @param
or @default
. It also optionally reports the presence of the
square-bracketed optional arguments at all.
The rule is intended to prevent the indication of defaults on tags where
this would be redundant with ES6 default parameters (or for @default
,
where it would be redundant with the context to which the @default
tag is attached).
Unless your @default
is on a function, you will need to set contexts
to an appropriate context, including, if you wish, "any".
Options
noOptionalParamNames
Set this to true
to report the presence of optional parameters. May be
used if the project is insisting on optionality being indicated by
the presence of ES6 default parameters (bearing in mind that such
"defaults" are only applied when the supplied value is missing or
undefined
but not for null
or other "falsey" values).
contexts
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to "any"
if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
expression, i.e., @callback
or @function
(or its aliases @func
or
@method
) (including those associated with an @interface
).
See the "AST and Selectors"
section of our README for more on the expected format.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | param , default |
Aliases | arg , argument , defaultvalue |
Recommended | false |
Options | contexts , noOptionalParamNames |
The following patterns are considered problems:
function quux (foo) {
}
class Test {
quux (foo) {
}
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
const a = {};
const a = {};
The following patterns are not considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
const a = {};
no-missing-syntax
This rule lets you report when certain comment structures are always expected.
This rule might be especially useful with overrides
where you need only require tags and/or types within specific directories
(e.g., to enforce that a plugins or locale directory always has a certain form
of export).
This (along with no-restricted-syntax
) is a bit similar to Schematron for
XML or jsontron for JSON--you can validate expectations of there being
arbitrary structures.
This differs from the rule of the same name in eslint-plugin-query
in that this always looks for a comment above a structure (whether or not
you have a comment
condition).
In addition to being generally useful for precision in requiring contexts,
it is hoped that the ability to specify required tags on structures can
be used for requiring @type
or other types for a minimalist yet adequate
specification of types which can be used to compile JavaScript+JSDoc (JJ)
to WebAssembly (e.g., by converting it to TypeSscript and then using
AssemblyScript to convert to WebAssembly). (It may be possible that one
will need to require types with certain structures beyond function
declarations and the like, as well as optionally requiring specification
of number types.)
Note that you can use selectors which make use of negators like :not()
including with asterisk, e.g., *:not(FunctionDeclaration)
to indicate types
which are not adequate to satisfy a condition, e.g.,
FunctionDeclaration:not(FunctionDeclaration[id.name="ignoreMe"])
would
not report if there were only a function declaration of the name "ignoreMe"
(though it would report by function declarations of other names).
Options
contexts
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Use the minimum
property (defaults to 1) to indicate how many are required
for the rule to be reported.
Use the message
property to indicate the specific error to be shown when an
error is reported for that context being found missing. You may use
{{context}}
and {{comment}}
with such messages.
Set to "any"
if you want the rule to apply to any jsdoc block throughout
your files (as is necessary for finding function blocks not attached to a
function declaration or expression, i.e., @callback
or @function
(or its
aliases @func
or @method
) (including those associated with an @interface
).
See the "AST and Selectors"
section of our README for more on the expected format.
| |
---|
Context | None except those indicated by contexts |
Tags | Any if indicated by AST |
Recommended | false |
Options | contexts |
The following patterns are considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
function bar () {
}
function baz () {
}
no-multi-asterisks
Prevents use of multiple asterisks at the beginning of lines.
Note that if you wish to prevent multiple asterisks at the very beginning of
the jsdoc block, you should use no-bad-blocks
(as that is not proper jsdoc
and that rule is for catching blocks which only seem like jsdoc).
Options
preventAtMiddleLines
(defaults to true
)
Prevent the likes of this:
preventAtEnd
(defaults to true
)
Prevent the likes of this:
| |
---|
Context | everywhere |
Tags | (any) |
Recommended | true |
Settings | |
Options | preventAtEnd , preventAtMiddleLines |
The following patterns are considered problems:
The following patterns are not considered problems:
function foo() {
}
function foo(): void {
}
function foo() {
}
no-restricted-syntax
Reports when certain comment structures are present.
Note that this rule differs from ESLint's no-restricted-syntax
rule in expecting values within a single options object's
contexts
property, and with the property context
being used in place of
selector
(as well as allowing for comment
). The format also differs from
the format expected by eslint-plugin-query
.
Unlike those rules, this is specific to finding comments attached to
structures, (whether or not you add a specific comment
condition).
Note that if your parser supports comment AST (as jsdoc-eslint-parser/ is designed to do), you can just use ESLint's
rule.
Options
contexts
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Use the message
property to indicate the specific error to be shown when an
error is reported for that context being found.
Set to "any"
if you want the rule to apply to any jsdoc block throughout
your files (as is necessary for finding function blocks not attached to a
function declaration or expression, i.e., @callback
or @function
(or its
aliases @func
or @method
) (including those associated with an @interface
).
See the "AST and Selectors"
section of our README for more on the expected format.
| |
---|
Context | None except those indicated by contexts |
Tags | Any if indicated by AST |
Recommended | false |
Options | contexts |
The following patterns are considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
no-types
This rule reports types being used on @param
or @returns
.
The rule is intended to prevent the indication of types on tags where
the type information would be redundant with TypeScript.
Options
contexts
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to "any"
if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
expression, i.e., @callback
or @function
(or its aliases @func
or
@method
) (including those associated with an @interface
).
See the "AST and Selectors"
section of our README for more on the expected format.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | param , returns |
Aliases | arg , argument , return |
Recommended | false |
Options | contexts |
The following patterns are considered problems:
function quux (foo) {
}
class quux {
bar (foo) {
}
}
function quux (foo) {
}
class quux {
quux (foo) {
}
}
function quux () {
}
function quux () {
}
The following patterns are not considered problems:
function quux (foo) {
}
no-undefined-types
Checks that types in jsdoc comments are defined. This can be used to check
unimported types.
When enabling this rule, types in jsdoc comments will resolve as used
variables, i.e. will not be marked as unused by no-unused-vars
.
In addition to considering globals found in code (or in ESLint-indicated
globals
) as defined, the following tags will also be checked for
name(path) definitions to also serve as a potential "type" for checking
the tag types in the table below:
@callback
, @class
(or @constructor
), @constant
(or @const
),
@event
, @external
(or @host
), @function
(or @func
or @method
),
@interface
, @member
(or @var
), @mixin
, @name
, @namespace
,
@template
(for "closure" or "typescript" settings.jsdoc.mode
only),
@typedef
.
The following tags will also be checked but only when the mode is closure
:
@package
, @private
, @protected
, @public
, @static
The following types are always considered defined.
null
, undefined
, void
, string
, boolean
, object
,
function
, symbol
number
, bigint
, NaN
, Infinity
any
, *
this
, true
, false
Array
, Object
, RegExp
, Date
, Function
Note that preferred types indicated within settings.jsdoc.preferredTypes
will
also be assumed to be defined.
Also note that if there is an error parsing
types for a tag, the function will silently ignore that tag, leaving it to
the valid-types
rule to report parsing errors.
If you define your own tags, you can use settings.jsdoc.structuredTags
to indicate that a tag's name
is "namepath-defining" (and should prevent
reporting on use of that namepath elsewhere) and/or that a tag's type
is
false
(and should not be checked for types). If the type
is an array, that
array's items will be considered as defined for the purposes of that tag.
Options
An option object may have the following key:
definedTypes
- This array can be populated to indicate other types which
are automatically considered as defined (in addition to globals, etc.).
Defaults to an empty array.
| |
---|
Context | everywhere |
Tags | augments , class , constant , enum , implements , member , module , namespace , param , property , returns , throws , type , typedef , yields |
Aliases | constructor , const , extends , var , arg , argument , prop , return , exception , yield |
Closure-only | package , private , protected , public , static |
Recommended | true |
Options | definedTypes |
Settings | preferredTypes , mode , structuredTags |
The following patterns are considered problems:
function quux(foo, bar, baz) {
}
function quux(foo, bar, baz) {
}
function quux(foo) {
}
function quux(foo, bar) {
}
function quux(foo, bar, baz) {
}
function quux(foo, bar, baz) {
}
function foo (bar) {
};
class Foo {
bar () {
}
}
class Foo {
invalidTemplateReference () {
}
}
class Bar {
validTemplateReference () {
}
}
var quux = {
};
class Foo {
bar (baz) {
}
}
function quux (varargs) {
}
function quux () {}
function quux () {}
function quux () {}
function quux () {}
function foo (bar) {
};
The following patterns are not considered problems:
function quux(foo) {
}
function quux(foo) {
}
class MyClass {}
function quux(foo) {
console.log(foo);
}
quux(0);
const MyType = require('my-library').MyType;
function quux(foo) {
}
const MyType = require('my-library').MyType;
function quux(foo) {
}
const MyType = require('my-library').MyType;
function quux(foo) {
}
import {MyType} from 'my-library';
function quux(foo, bar, baz) {
}
function quux(foo, bar) {
}
function quux(foo) {
}
function quux(foo) {
}
function testFunction(callback) {
callback();
}
function foo () {
}
function foo () {
}
function quux(foo, bar) {
}
function quux(foo, bar, baz) {
}
function quux(foo, bar, baz) {
}
function foo (bar) {
};
class Foo {
bar () {
}
}
class Foo {
bar () {}
baz () {}
}
class Foo {
bar (baz) {
}
}
class Foo {
bar (baz) {
}
}
function quux () {
}
function registerEvent(obj, method, callback) {
}
function quux (varargs) {
}
function quux (varargs) {
}
class Navigator {}
function quux () {}
class SomeType {}
function quux () {}
function example(arg) {
function inner(x) {
}
}
const init = () => {
function request() {
return Promise.resolve('success');
}
};
exports.resolve1 = function resolve1(value) {
return Promise.resolve(value);
};
function quux () {}
function quux () {}
class Test {
method (): this {
return this;
}
}
require-asterisk-prefix
Requires that each JSDoc line starts with an *
.
Options
This rule allows an optional string argument. If it is "always"
then a
problem is raised when there is no asterisk prefix on a given jsdoc line. If
it is "never"
then a problem is raised when there is an asterisk present.
The default value is "always"
. You may also set the default to "any"
and use the tags
option to apply to specific tags only.
After the string option, one may add an object with the following.
tags
If you want different values to apply to specific tags, you may use
the tags
option object. The keys are always
, never
, or any
and
the values are arrays of tag names or the special value *description
which applies to the main jsdoc block description.
{
'jsdoc/require-asterisk-prefix': ['error', 'always', {
tags: {
always: ['*description'],
any: ['example', 'license'],
never: ['copyright']
}
}]
}
| |
---|
Context | everywhere |
Tags | All or as limited by the tags option |
Options | (a string matching `"always" |
The following patterns are considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
The following patterns are not considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
require-description-complete-sentence
Requires that block description, explicit @description
, and
@param
/@returns
tag descriptions are written in complete sentences, i.e.,
- Description must start with an uppercase alphabetical character.
- Paragraphs must start with an uppercase alphabetical character.
- Sentences must end with a period.
- Every line in a paragraph (except the first) which starts with an uppercase
character must be preceded by a line ending with a period.
- A colon or semi-colon followed by two line breaks is still part of the
containing paragraph (unlike normal dual line breaks).
- Text within inline tags
{...}
are not checked for sentence divisions. - Periods after items within the
abbreviations
option array are not treated
as sentence endings.
Options
tags
If you want additional tags to be checked for their descriptions, you may
add them within this option.
{
'jsdoc/require-description-complete-sentence': ['error', {
tags: ['see', 'copyright']
}]
}
The tags @param
/@arg
/@argument
and @property
/@prop
will be properly
parsed to ensure that the checked "description" text includes only the text
after the name.
All other tags will treat the text following the tag name, a space, and
an optional curly-bracketed type expression (and another space) as part of
its "description" (e.g., for @returns {someType} some description
, the
description is some description
while for @some-tag xyz
, the description
is xyz
).
abbreviations
You can provide an abbreviations
options array to avoid such strings of text
being treated as sentence endings when followed by dots. The .
is not
necessary at the end of the array items.
newlineBeforeCapsAssumesBadSentenceEnd
When false
(the new default), we will not assume capital letters after
newlines are an incorrect way to end the sentence (they may be proper
nouns, for example).
| |
---|
Context | everywhere |
Tags | doc block, param , returns , description , property , summary , file , classdesc , todo , deprecated , throws , 'yields' and others added by tags |
Aliases | arg , argument , return , desc , prop , fileoverview , overview , exception , yield |
Recommended | false |
Options | tags , abbreviations , newlineBeforeCapsAssumesBadSentenceEnd |
The following patterns are considered problems: | |
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function longDescription (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux (foo) {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function speak() {
}
function quux (foo) {
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
**
* Do not have dynamic content; e.g. homepage. Here a simple unique id
* suffices.
*/
function quux () {
}
function speak() {
}
export default (foo) => {
foo()
}
require-description
Requires that all functions have a description.
- All functions must have an implicit description (e.g., text above tags) or
have the option
descriptionStyle
set to tag
(requiring @description
(or @desc
if that is set as your preferred tag name)). - Every jsdoc block description (or
@description
tag if descriptionStyle
is "tag"
) must have a non-empty description that explains the purpose of
the method.
Options
An options object may have any of the following properties:
contexts
- Set to an array of strings representing the AST context
where you wish the rule to be applied (e.g., ClassDeclaration
for ES6
classes). Overrides the default contexts (see below). Set to "any"
if
you want the rule to apply to any jsdoc block throughout your files.exemptedBy
- Array of tags (e.g., ['type']
) whose presence on the
document block avoids the need for a @description
. Defaults to an
array with inheritdoc
. If you set this array, it will overwrite the
default, so be sure to add back inheritdoc
if you wish its presence
to cause exemption of the rule.descriptionStyle
- Whether to accept implicit descriptions ("body"
) or
@description
tags ("tag"
) as satisfying the rule. Set to "any"
to
accept either style. Defaults to "body"
.checkConstructors
- A value indicating whether constructor
s should be
checked. Defaults to true
.checkGetters
- A value indicating whether getters should be checked.
Defaults to true
.checkSetters
- A value indicating whether setters should be checked.
Defaults to true
.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | description or jsdoc block |
Aliases | desc |
Recommended | false |
Options | contexts , exemptedBy , descriptionStyle , checkConstructors , checkGetters , checkSetters |
Settings | overrideReplacesDocs , augmentsExtendsReplacesDocs , implementsReplacesDocs |
The following patterns are considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
class quux {
}
class quux {
}
class quux {
}
function quux () {
}
interface quux {
}
var quux = class {
};
var quux = {
};
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
class TestClass {
constructor() { }
}
class TestClass {
constructor() { }
}
class TestClass {
get Test() { }
}
class TestClass {
get Test() { }
}
class TestClass {
set Test(value) { }
}
class TestClass {
set Test(value) { }
}
class Foo {
constructor() {}
bar() {}
}
class quux {
}
class quux {
}
class quux {
}
class quux {
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
class quux {
}
function quux () {
}
function quux () {
}
interface quux {
}
interface quux {
checked?: boolean
}
var quux = class {
};
var quux = {
};
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
class TestClass {
constructor() { }
}
class TestClass {
constructor() { }
}
class TestClass {
get Test() { }
}
class TestClass {
get Test() { }
}
class TestClass {
set Test(value) { }
}
class TestClass {
set Test(value) { }
}
function quux () {
}
function quux () {
}
function quux () {
}
class quux {
}
class quux {
}
require-example
Requires that all functions have examples.
- All functions must have one or more
@example
tags. - Every example tag must have a non-empty description that explains the
method's usage.
Options
This rule has an object option.
exemptedBy
Array of tags (e.g., ['type']
) whose presence on the document
block avoids the need for an @example
. Defaults to an array with
inheritdoc
. If you set this array, it will overwrite the default,
so be sure to add back inheritdoc
if you wish its presence to cause
exemption of the rule.
exemptNoArguments
Boolean to indicate that no-argument functions should not be reported for
missing @example
declarations.
contexts
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
(e.g., ClassDeclaration
for ES6
classes). Overrides the default contexts (see below). Set to "any"
if you
want the rule to apply to any jsdoc block throughout your files.
See the "AST and Selectors"
section of our README for more on the expected format.
checkConstructors
A value indicating whether constructor
s should be checked.
Defaults to true
.
checkGetters
A value indicating whether getters should be checked. Defaults to false
.
checkSetters
A value indicating whether setters should be checked. Defaults to false
.
Fixer
The fixer for require-example
will add an empty @example
, but it will still
report a missing example description after this is added.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | example |
Recommended | false |
Options | exemptedBy , exemptNoArguments , avoidExampleOnConstructors , contexts |
Settings | overrideReplacesDocs , augmentsExtendsReplacesDocs , implementsReplacesDocs |
The following patterns are considered problems:
function quux () {
}
function quux (someParam) {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
class quux {
}
function quux () {
}
class TestClass {
get Test() { }
}
class TestClass {
get Test() { }
}
class TestClass {
set Test(value) { }
}
class TestClass {
set Test(value) { }
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
class Foo {
constructor () {
}
}
function quux () {
}
function quux () {
}
class quux {
}
function quux () {
}
class TestClass {
get Test() { }
}
class TestClass {
get Test() { }
}
class TestClass {
get Test() { }
}
class TestClass {
set Test(value) { }
}
class TestClass {
set Test(value) { }
}
class TestClass {
set Test(value) { }
}
function quux () {
}
require-file-overview
Checks that:
- All files have a
@file
, @fileoverview
, or @overview
tag. - Duplicate file overview tags within a given file will be reported
- File overview tags will be reported which are not, as per
the docs, "at the beginning of
the file"–where beginning of the file is interpreted in this rule
as being when the overview tag is not preceded by anything other than
a comment.
Options
tags
The keys of this object are tag names, and the values are configuration
objects indicating what will be checked for these whole-file tags.
Each configuration object has the following boolean keys (which default
to false
when this option is supplied): mustExist
, preventDuplicates
,
initialCommentsOnly
. These correspond to the three items above.
When no tags
is present, the default is:
{
"file": {
"initialCommentsOnly": true,
"mustExist": true,
"preventDuplicates": true,
}
}
You can add additional tag names and/or override file
if you supply this
option, e.g., in place of or in addition to file
, giving other potential
file global tags like @license
, @copyright
, @author
, @module
or
@exports
, optionally restricting them to a single use or preventing them
from being preceded by anything besides comments.
For example:
{
"license": {
"mustExist": true,
"preventDuplicates": true,
}
}
This would require one and only one @license
in the file, though because
initialCommentsOnly
is absent and defaults to false
, the @license
can be anywhere.
In the case of @license
, you can use this rule along with the
check-values
rule (with its allowedLicenses
or licensePattern
options),
to enforce a license whitelist be present on every JS file.
Note that if you choose to use preventDuplicates
with license
, you still
have a way to allow multiple licenses for the whole page by using the SPDX
"AND" expression, e.g., @license (MIT AND GPL-3.0)
.
Note that the tag names are the main jsdoc tag name, so you should use file
in this configuration object regardless of whether you have configured
fileoverview
instead of file
on tagNamePreference
(i.e., fileoverview
will be checked, but you must use file
on the configuration object).
| |
---|
Context | Everywhere |
Tags | file ; others when tags set |
Aliases | fileoverview , overview |
Recommended | false |
Options | tags |
The following patterns are considered problems:
function quux () {}
function quux () {}
function quux () {}
function quux () {}
function quux () {}
function quux () {}
function quux (a) {}
function quux (a) {}
function bar (b) {}
function quux () {
}
function quux () {
}
function quux () {
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
var a
require-hyphen-before-param-description
Requires (or disallows) a hyphen before the @param
description.
Options
This rule takes one optional string argument and an optional options object.
If the string is "always"
then a problem is raised when there is no hyphen
before the description. If it is "never"
then a problem is raised when there
is a hyphen before the description. The default value is "always"
.
The options object may have the following properties to indicate behavior for
other tags besides the @param
tag (or the @arg
tag if so set):
tags
- Object whose keys indicate different tags to check for the
presence or absence of hyphens; the key value should be "always" or "never",
indicating how hyphens are to be applied, e.g., {property: 'never'}
to ensure @property
never uses hyphens. A key can also be set as *
, e.g.,
'*': 'always'
to apply hyphen checking to any tag (besides the preferred
@param
tag which follows the main string option setting and besides any
other tags
entries).
| |
---|
Context | everywhere |
Tags | param and optionally other tags within tags |
Aliases | arg , argument ; potentially prop or other aliases |
Recommended | false |
Options | a string matching "always" or "never" followed by an optional object with a tags property |
The following patterns are considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux (foo) {
}
function quux () {
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function main(argv) {
};
require-jsdoc
Checks for presence of jsdoc comments, on class declarations as well as
functions.
Options
Accepts one optional options object with the following optional keys.
publicOnly
This option will insist that missing jsdoc blocks are only reported for
function bodies / class declarations that are exported from the module.
May be a boolean or object. If set to true
, the defaults below will be
used. If unset, jsdoc block reporting will not be limited to exports.
This object supports the following optional boolean keys (false
unless
otherwise noted):
ancestorsOnly
- Only check node ancestors to check if node is exportedesm
- ESM exports are checked for JSDoc comments (Defaults to true
)cjs
- CommonJS exports are checked for JSDoc comments (Defaults to true
)window
- Window global exports are checked for JSDoc comments
require
An object with the following optional boolean keys which all default to
false
except as noted, indicating the contexts where the rule will apply:
ArrowFunctionExpression
ClassDeclaration
ClassExpression
FunctionDeclaration
(defaults to true
)FunctionExpression
MethodDefinition
contexts
Set this to an array of strings or objects representing the additional AST
contexts where you wish the rule to be applied (e.g., Property
for
properties). If specified as an object, it should have a context
property
and can have an inlineCommentBlock
property which, if set to true
, will
add an inline /** */
instead of the regular, multi-line, indented jsdoc
block which will otherwise be added. Defaults to an empty array.
Note that you may need to disable require
items (e.g., MethodDefinition
)
if you are specifying a more precise form in contexts
(e.g., MethodDefinition:not([accessibility="private"] > FunctionExpression
).
See the "AST and Selectors"
section of our README for more on the expected format.
exemptEmptyConstructors
Default: true
When true
, the rule will not report missing jsdoc blocks above constructors
with no parameters or return values (this is enabled by default as the class
name or description should be seen as sufficient to convey intent).
exemptEmptyFunctions
Default: false.
When true
, the rule will not report missing jsdoc blocks above
functions/methods with no parameters or return values (intended where
function/method names are sufficient for themselves as documentation).
checkConstructors
A value indicating whether constructor
s should be checked. Defaults to
true
. When true
, exemptEmptyConstructors
may still avoid reporting when
no parameters or return values are found.
checkGetters
A value indicating whether getters should be checked. Besides setting as a
boolean, this option can be set to the string "no-setter"
to indicate that
getters should be checked but only when there is no setter. This may be useful
if one only wishes documentation on one of the two accessors. Defaults to
false
.
checkSetters
A value indicating whether setters should be checked. Besides setting as a
boolean, this option can be set to the string "no-getter"
to indicate that
setters should be checked but only when there is no getter. This may be useful
if one only wishes documentation on one of the two accessors. Defaults to
false
.
enableFixer
A boolean on whether to enable the fixer (which adds an empty jsdoc block).
Defaults to true
.
| |
---|
Context | ArrowFunctionExpression , ClassDeclaration , ClassExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | N/A |
Recommended | true |
Options | publicOnly , require , contexts , exemptEmptyConstructors , exemptEmptyFunctions , enableFixer |
The following patterns are considered problems:
export interface Foo {
tom: string;
catchJerry(): boolean;
}
export interface Foo {
tom: string;
jerry: number;
}
export interface Foo {
bar(): string;
}
export interface Foo {
bar: string;
}
export interface Foo extends Bar {
baz(): void;
meow(): void;
}
function quux (foo) {
}
function myFunction() {
}
function myFunction() {
}
function myFunction() {
}
function myFunction() {
}
export var test = function () {
};
function test () {
}
export var test2 = test;
export const test = () => {
};
export const test = () => {
};
export const test = () => {
};
export let test = class {
};
export default function () {}
export default () => {}
export default (function () {})
export default class {}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function myFunction() {}
class A {
constructor(xs) {
this.a = xs;
}
}
class A {
constructor(xs) {
this.a = xs;
}
}
class A extends B {
constructor(xs) {
this.a = xs;
}
}
export class A extends B {
constructor(xs) {
this.a = xs;
}
}
export default class A extends B {
constructor(xs) {
this.a = xs;
}
}
var myFunction = () => {}
var myFunction = () => () => {}
var foo = function() {}
const foo = {bar() {}}
var foo = {bar: function() {}}
function foo (abc) {}
function foo () {
return true;
}
module.exports = function quux () {
}
module.exports = function quux () {
}
module.exports = {
method: function() {
}
}
module.exports = {
test: {
test2: function() {
}
}
}
module.exports = {
test: {
test2: function() {
}
}
}
const test = module.exports = function () {
}
const test = module.exports = function () {
}
test.prototype.method = function() {}
const test = function () {
}
module.exports = {
test: test
}
const test = () => {
}
module.exports = {
test: test
}
class Test {
method() {
}
}
module.exports = Test;
export default function quux () {
}
export default function quux () {
}
function quux () {
}
export default quux;
export function test() {
}
export function test() {
}
var test = function () {
}
var test2 = 2;
export { test, test2 }
var test = function () {
}
export { test as test2 }
export default class A {
}
export default class A {
}
var test = function () {
}
window.test = function () {
}
function test () {
}
module.exports = function() {
}
export function someMethod() {
}
export function someMethod() {
}
const myObject = {
myProp: true
};
export interface Foo extends Bar {
baz(): void;
meow(): void;
}
class MyClass {
someProperty: boolean;
}
export default class Test {
constructor(a) {
this.a = a;
}
}
export default class Test {
constructor(a) {
this.a = a;
}
private abc(a) {
this.a = a;
}
}
e = function () {
};
export class Class {
test = 1;
foo() {
this.test = 2;
}
}
class Dog {
eat() {
}
}
const hello = name => {
document.body.textContent = "Hello, " + name + "!";
};
export const loginSuccessAction = (): BaseActionPayload => ({ type: LOGIN_SUCCESSFUL });
export type Container = {
constants?: ObjByString;
enums?: { [key in string]: TypescriptEnum };
helpers?: { [key in string]: AnyFunction };
};
class Foo {
constructor() {}
bar() {}
}
class Example extends React.PureComponent {
componentDidMount() {}
render() {}
someOtherMethod () {}
}
function foo(arg: boolean): boolean {
return arg;
}
function bar(arg: true): true;
function bar(arg: false): false;
function bar(arg: boolean): boolean {
return arg;
}
export function foo(arg: boolean): boolean {
return arg;
}
export function bar(arg: true): true;
export function bar(arg: false): false;
export function bar(arg: boolean): boolean {
return arg;
}
module.exports.foo = (bar) => {
return bar + "biz"
}
class Animal {
#name: string;
private species: string;
public color: string;
@SomeAnnotation('optionalParameter')
tail: boolean;
}
@Entity('users')
export class User {}
class Foo {
constructor() {}
}
class Foo {
constructor(notEmpty) {}
}
class Foo {
constructor() {
const notEmpty = true;
return notEmpty;
}
}
function quux() {
}
class Test {
aFunc() {}
}
class Test {
aFunc = () => {}
anotherFunc() {}
}
export enum testEnum {
A, B
}
export interface Test {
aFunc: () => void;
aVar: string;
}
export type testType = string | number;
export interface Foo {
bar: number;
baz: string;
quux(): void;
}
export class MyComponentComponent {
@Output()
public changed = new EventEmitter();
public test = 'test';
@Input()
public value = new EventEmitter();
}
requestAnimationFrame(draw)
function bench() {
}
class Foo {
set aName (val) {}
}
class Foo {
get aName () {}
}
const obj = {
get aName () {},
}
The following patterns are not considered problems:
interface FooBar {
fooBar: string;
}
interface FooBar {
fooBar: string;
}
export class Foo {
someMethod() {
interface FooBar {
fooBar: string;
}
}
}
function someFunciton() {
interface FooBar {
fooBar: string;
}
}
export function foo() {
interface bar {
fooBar: string;
}
}
var array = [1,2,3];
array.forEach(function() {});
function MyClass() {}
function myFunction() {}
var myFunction = function() {};
Object.myFunction = function () {};
var obj = {
myFunction: function () {} };
function myFunction() {}
function myFunction() {}
function myFunction() {}
var myFunction = function () {}
var myFunction = function () {}
var myFunction = function () {}
Object.myFunction = function() {}
Object.myFunction = function() {}
Object.myFunction = function() {}
(function(){})();
var object = {
myFunction: function() {} }
var object = {
myFunction: function() {} }
var object = {
myFunction: function() {} }
var array = [1,2,3];
array.filter(function() {});
Object.keys(this.options.rules || {}).forEach(function(name) {}.bind(this));
var object = { name: 'key'};
Object.keys(object).forEach(function() {})
function myFunction() {
}
function myFunction() {
}
function myFunction() {
}
function myFunction() {
}
function myFunction() {}
var myFunction = function() {}
class A {
constructor(xs) {
this.a = xs;
}
}
class App extends Component {
constructor(xs) {
this.a = xs;
}
}
export default class App extends Component {
constructor(xs) {
this.a = xs;
}
}
export class App extends Component {
constructor(xs) {
this.a = xs;
}
}
class A {
constructor(xs) {
this.a = xs;
}
}
var myFunction = () => {}
var myFunction = function () {}
var myFunction = () => {}
var myFunction = () => () => {}
setTimeout(() => {}, 10);
var foo = function() {}
const foo = {
bar() {}}
var foo = {
bar: function() {}}
var foo = { [function() {}]: 1 };
function foo () {}
function foo () {
return;
}
const test = {};
test.method = function () {
}
module.exports = {
prop: { prop2: test.method }
}
function test() {
}
module.exports = {
prop: { prop2: test }
}
test = function() {
}
module.exports = {
prop: { prop2: test }
}
test = function() {
}
exports.someMethod = {
prop: { prop2: test }
}
const test = () => {
}
module.exports = {
prop: { prop2: test }
}
const test = () => {
}
module.exports = {
prop: { prop2: test }
}
window.test = function() {
}
module.exports = {
prop: window
}
test = function() {
}
test = function() {
}
module.exports = {
prop: { prop2: test }
}
test = function() {
}
test = 2;
module.exports = {
prop: { prop2: test }
}
function test() {
}
test.prototype.method = function() {
}
module.exports = {
prop: { prop2: test }
}
class Test {
method() {
}
}
module.exports = Test;
export default function quux () {
}
export default function quux () {
}
function quux () {
}
export default quux;
function quux () {
}
export default quux;
export function test() {
}
export function test() {
}
var test = function () {
}
var test2 = 2;
export { test, test2 }
var test = function () {
}
export { test as test2 }
export default class A {
}
var test = function () {
}
let test = function () {
}
let test = class {
}
let test = class {
}
export function someMethod() {
}
export function someMethod() {
}
exports.someMethod = function() {
}
const myObject = {
myProp: true
};
function bear() {}
function quux () {
}
export default quux;
export interface Example {
test: string
}
interface Example {
test: string
}
export type Example = {
test: string
};
type Example = {
test: string
};
export enum Example {
test = 123
}
enum Example {
test = 123
}
const foo = {...{}};
function bar() {}
@logged
export default class Foo {
}
const a = {};
const b = {
...a
};
export default b;
export interface Foo extends Bar {
baz(): void;
meow(): void;
}
export default class Test {
private abc(a) {
this.a = a;
}
}
@Controller()
export class AppController {
@Get('/info')
public getInfo(): string {
return 'OK';
}
}
@Entity('users')
export class User {
}
@Entity('users', getVal())
export class User {
}
class Foo {
constructor() {}
}
class Foo {
constructor() {}
}
class Foo {
get aName () {}
set aName (val) {}
}
const obj = {
get aName () {},
set aName (val) {}
}
class Foo {
set aName (val) {}
}
class Foo {
get aName () {}
}
class Foo {
set aName (val) {}
}
class Foo {
get aName () {}
}
class Foo {
get aName () {}
set aName (val) {}
}
class Base {
constructor() {
}
}
export function a();
export function foo(): void {
function bar(): void {
console.log('bar');
}
console.log('foo');
}
const foo = {
bar: () => {
}
}
@Injectable({
providedIn: 'root',
})
@State<Partial<UserSettingsStateModel>>
({
name: 'userSettings',
defaults: {
isDev: !environment.production,
},
})
export class UserSettingsState { }
@Entity('users')
export class User {
}
require-param-description
Requires that each @param
tag has a description
value.
Options
contexts
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to "any"
if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
expression, i.e., @callback
or @function
(or its aliases @func
or
@method
) (including those associated with an @interface
).
See the "AST and Selectors"
section of our README for more on the expected format.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | param |
Aliases | arg , argument |
Recommended | true |
Options | contexts |
The following patterns are considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
The following patterns are not considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
require-param-name
Requires that all function parameters have names.
The @param
tag requires you to specify the name of the parameter you are documenting. You can also include the parameter's type, enclosed in curly brackets, and a description of the parameter.
JSDoc
Options
contexts
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to "any"
if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
expression, i.e., @callback
or @function
(or its aliases @func
or
@method
) (including those associated with an @interface
).
See the "AST and Selectors"
section of our README for more on the expected format.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | param |
Aliases | arg , argument |
Recommended | true |
Options | contexts |
The following patterns are considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
The following patterns are not considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function processData(processor) {
return processor(data)
}
function example(cb) {
cb(42);
}
require-param-type
Requires that each @param
tag has a type
value.
Options
contexts
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to "any"
if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
expression, i.e., @callback
or @function
(or its aliases @func
or
@method
) (including those associated with an @interface
).
See the "AST and Selectors"
section of our README for more on the expected format.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | param |
Aliases | arg , argument |
Recommended | true |
Options | contexts |
The following patterns are considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
The following patterns are not considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
require-param
Requires that all function parameters are documented.
Fixer
Adds @param <name>
for each tag present in the function signature but
missing in the jsdoc. Can be disabled by setting the enableFixer
option to false
.
Destructured object and array naming
When the fixer is applied to destructured objects, only the input name is
used.
So for:
function quux ({foo: bar, baz: bax = 5}) {
}
..the fixed jsdoc will be:
This is because the input to the function is the relevant item for
understanding the function's input, not how the variable is renamed
for internal use (the signature itself documents that).
For destructured arrays, the input name is merely the array index.
So for:
function quux ([foo, bar]) {
}
..the fixed jsdoc will be:
Missing root fixing
Note that unless enableRootFixer
(or enableFixer
) is set to false
,
missing roots will be added and auto-incremented. The default behavior
is for "root" to be auto-inserted for missing roots, followed by a
0-based auto-incrementing number.
So for:
function quux ({foo}, {bar}, {baz}) {
}
...the default jsdoc that would be added if the fixer is enabled would be:
The name of "root" can be configured with unnamedRootBase
(which also allows
cycling through a list of multiple root names before there is need for any
numeric component).
And one can have the count begin at another number (e.g., 1
) by changing
autoIncrementBase
from the default of 0
.
Rest Element (RestElement
) insertions
The fixer will automatically report/insert
jsdoc repeatable parameters
if missing.
function baar ([a, ...extra]) {
}
..becomes:
function baar ([a, ...extra]) {
}
Note that the type any
is included since we don't know of any specific
type to use.
To disable such rest element insertions, set enableRestElementFixer
to
false
.
Note too that the following will be reported even though there is an item
corresponding to extra
:
function baar ([a, ...extra]) {
}
...because it does not use the ...
syntax in the type.
Object Rest Property insertions
If the checkRestProperty
option is set to true
(false
by default),
missing rest properties will be reported with documentation auto-inserted:
function quux ({num, ...extra}) {
}
...becomes:
function quux ({num, ...extra}) {
}
You may wish to manually note in your jsdoc for extra
that this is a
rest property, however, as jsdoc
does not appear
to currently support syntax or output to distinguish rest properties from
other properties, so in looking at the docs alone without looking at the
function signature, it may appear that there is an actual property named
extra
.
Options
An options object accepts the following optional properties:
enableFixer
Whether to enable the fixer. Defaults to true
.
enableRootFixer
Whether to enable the auto-adding of incrementing roots (see the "Fixer"
section). Defaults to true
. Has no effect if enableFixer
is set to
false
.
enableRestElementFixer
Whether to enable the rest element fixer (see
"Rest Element (RestElement
) insertions"). Defaults to true
.
checkRestProperty
If set to true
, will report (and add fixer insertions) for missing rest
properties. Defaults to false
.
If set to true
, note that you can still document the subproperties of the
rest property using other jsdoc features, e.g., @typedef
:
function quux ({num, ...extra}) {
}
Setting this option to false
(the default) may be useful in cases where
you already have separate @param
definitions for each of the properties
within the rest property.
For example, with the option disabled, this will not give an error despite
extra
not having any definition:
function quux ({num, ...extra}) {
}
Nor will this:
function quux ({num, ...extra}) {
}
autoIncrementBase
Numeric to indicate the number at which to begin auto-incrementing roots.
Defaults to 0
.
unnamedRootBase
An array of root names to use in the fixer when roots are missing. Defaults
to ['root']
. Note that only when all items in the array besides the last
are exhausted will auto-incrementing occur. So, with
unnamedRootBase: ['arg', 'config']
, the following:
function quux ({foo}, [bar], {baz}) {
}
...will get the following jsdoc block added:
exemptedBy
Array of tags (e.g., ['type']
) whose presence on the document block
avoids the need for a @param
. Defaults to an array with
inheritdoc
. If you set this array, it will overwrite the default,
so be sure to add back inheritdoc
if you wish its presence to cause
exemption of the rule.
checkTypesPattern
When one specifies a type, unless it is of a generic type, like object
or array
, it may be considered unnecessary to have that object's
destructured components required, especially where generated docs will
link back to the specified type. For example:
export const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
By default checkTypesPattern
is set to
/^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$/u
,
meaning that destructuring will be required only if the type of the @param
(the text between curly brackets) is a match for "Object" or "Array" (with or
without initial caps), "PlainObject", or "GenericObject", "GenericArray" (or
if no type is present). So in the above example, the lack of a match will
mean that no complaint will be given about the undocumented destructured
parameters.
Note that the /
delimiters are optional, but necessary to add flags.
Defaults to using (only) the u
flag, so to add your own flags, encapsulate
your expression as a string, but like a literal, e.g., /^object$/ui
.
You could set this regular expression to a more expansive list, or you
could restrict it such that even types matching those strings would not
need destructuring.
contexts
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Overrides the default contexts (see below). May be useful for adding such as
TSMethodSignature
in TypeScript or restricting the contexts
which are checked.
See the "AST and Selectors"
section of our README for more on the expected format.
checkConstructors
A value indicating whether constructor
s should be checked. Defaults to
true
.
checkGetters
A value indicating whether getters should be checked. Defaults to false
.
checkSetters
A value indicating whether setters should be checked. Defaults to false
.
checkDestructured
Whether to require destructured properties. Defaults to true
.
checkDestructuredRoots
Whether to check the existence of a corresponding @param
for root objects
of destructured properties (e.g., that for function ({a, b}) {}
, that there
is something like @param myRootObj
defined that can correspond to
the {a, b}
object parameter).
If checkDestructuredRoots
is false
, checkDestructured
will also be
implied to be false
(i.e., the inside of the roots will not be checked
either, e.g., it will also not complain if a
or b
do not have their own
documentation). Defaults to true
.
useDefaultObjectProperties
Set to true
if you wish to expect documentation of properties on objects
supplied as default values. Defaults to false
.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | param |
Aliases | arg , argument |
Recommended | true |
Options | autoIncrementBase , checkDestructured , checkDestructuredRoots , contexts , enableFixer , enableRootFixer , enableRestElementFixer , checkRestProperty , exemptedBy , checkConstructors , checkGetters , checkSetters , checkTypesPattern , unnamedRootBase , useDefaultObjectProperties |
Settings | overrideReplacesDocs , augmentsExtendsReplacesDocs , implementsReplacesDocs |
The following patterns are considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux ({foo}) {
}
function quux (foo, bar, {baz}) {
}
function quux (foo, bar, {baz}) {
}
function quux ({foo}) {
}
function quux ({foo: bar = 5} = {}) {
}
function quux ({foo}) {
}
function quux ({foo}) {
}
function quux ({foo}) {
}
function quux ({ foo, bar: { baz }}) {
}
function quux ({foo}, {bar}) {
}
function quux ({foo}, {bar}) {
}
function quux ({foo}, {bar}) {
}
function quux (foo, bar) {
}
function quux (foo, bar) {
}
function quux (foo, bar, baz) {
}
function quux (foo, bar, baz) {
}
function quux (foo, bar, baz) {
}
function quux (foo) {
}
function quux (foo, bar) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
class A {
quux (foo) {
}
}
class A {
quux (foo) {
}
}
class A {
quux (foo) {
}
}
class A {
quux (foo) {
}
}
export class SomeClass {
constructor(private property: string, private foo: number) {}
}
function quux (foo) {
}
function quux ({bar, baz}, foo) {
}
function quux (foo, {bar, baz}) {
}
function quux ([bar, baz], foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function assign (employees, name) {
};
interface ITest {
TestMethod(id: number): void;
}
abstract class TestClass
{
abstract TestFunction(id);
}
declare class TestClass
{
TestMethod(id);
}
declare let TestFunction: (id) => void;
let TestFunction: (id) => void;
function test(
processor: (id: number) => string
) {
return processor(10);
}
let test = (processor: (id: number) => string) =>
{
return processor(10);
}
class TestClass {
public Test: (id: number) => string;
}
class TestClass {
public TestMethod(): (id: number) => string
{
}
}
interface TestInterface {
public Test: (id: number) => string;
}
interface TestInterface {
public TestMethod(): (id: number) => string;
}
function test(): (id: number) => string;
let test = (): (id: number) => string =>
{
return (id) => `${id}`;
}
function quux (baz, {foo: bar}) {
}
class Client {
async setData(
data: { last_modified?: number },
options: {
headers?: Record<string, string>;
safe?: boolean;
retry?: number;
patch?: boolean;
last_modified?: number;
permissions?: [];
} = {}
) {}
}
function quux (foo) {
}
class Client {
async setData(
data: { last_modified?: number }
) {}
}
function quux ({num, ...extra}) {
}
function quux ({opts: {num, ...extra}}) {
}
function baar ([a, ...extra]) {
}
function baar (a, ...extra) {
}
const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
module.exports = class GraphQL {
fetch = ({ url, ...options }, cacheKey) => {
}
};
(function() {
function f(param) {
return !param;
}
})();
function quux ({ foo: { bar } }) {}
function quux ({ foo: { bar } }) {}
function quux ({ foo: { bar } }) {}
function quux ({ foo: { bar } }) {}
function foo({ foo: { bar: { baz } }}) {}
export function testFn1 ({ prop = { a: 1, b: 2 } }) {
}
The following patterns are not considered problems:
function quux (foo) {
}
function quux ({foo}) {
}
function quux ({foo}, {bar}) {
}
function quux ({foo}, {bar}) {
}
function quux ({foo}, {bar}, {baz}) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
class A {
quux (foo) {
}
}
function quux (foo) {
}
class A {
quux (foo) {
}
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
class A {
quux (foo) {
}
}
class A {
quux (foo) {
}
}
class A {
quux (foo) {
}
}
class A {
quux (foo) {
}
}
class A {
quux (foo) {
}
}
class A {
quux (foo) {
}
}
class A {
quux (foo) {
}
}
class A {
quux (foo) {
}
}
class A {
quux (foo) {
}
}
class A {
quux (foo) {
}
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
const test = something?.find(_ => _)
function foo(req, res, next) {}
function quux () {
}
var A = class {
quux (foo) {
}
}
export class SomeClass {
constructor(private property: string) {}
}
function assign({name, department}) {
}
export abstract class StephanPlugin<O, D> {
public constructor({options, client}: {
options: O;
client: unknown;
}, defaultOptions: D) {
}
}
function quux (foo) {
}
let test = (): (id: number) => string =>
{
return (id) => `${id}`;
}
class base {
constructor(arg0) {}
}
class foo extends base {
constructor(arg0) {
super(arg0);
this.arg0 = arg0;
}
}
export abstract class StephanPlugin<O, D> {
public constructor({ options, client: { name } }: {
options: O;
client: { name: string };
}, defaultOptions: D) {
}
}
function createGetter (cb) {
return function (...args) {
cb();
};
}
function quux ({num, ...extra}) {
}
function baar ([a, ...extra]) {
}
function baar (a, ...extra) {
}
const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
class CSS {
setCssObject(propertyObject: {[key: string]: string | number}): void {
}
}
function quux (foo, bar, {baz}) {
}
function quux (foo, bar, {baz}) {
}
function quux ({"foo": bar}) {
}
function quux ({foo: bar}) {
}
module.exports = function a(b) {
console.info(b);
};
function quux ({ foo: { bar } }) {}
function quux ({ foo: { bar } }) {}
function Item({
data: [foo, bar, ...baz],
defaulting: [quux, xyz] = []
}) {
}
export function testFn1 ({ prop = { a: 1, b: 2 } }) {
}
require-property
Requires that all @typedef
and @namespace
tags have @property
when their type is a plain object
, Object
, or PlainObject
.
Note that any other type, including a subtype of object such as
object<string, string>
, will not be reported.
Fixer
The fixer for require-property
will add an empty @property
.
| |
---|
Context | Everywhere |
Tags | typedef , namespace |
Recommended | true |
The following patterns are considered problems:
class Test {
quux () {}
}
The following patterns are not considered problems:
function quux () {
}
require-property-description
Requires that each @property
tag has a description
value.
| |
---|
Context | everywhere |
Tags | property |
Aliases | prop |
Recommended | true |
The following patterns are considered problems:
The following patterns are not considered problems:
require-property-name
Requires that all function @property
tags have names.
| |
---|
Context | everywhere |
Tags | property |
Aliases | prop |
Recommended | true |
The following patterns are considered problems:
The following patterns are not considered problems:
require-property-type
Requires that each @property
tag has a type
value.
| |
---|
Context | everywhere |
Tags | property |
Aliases | prop |
Recommended | true |
The following patterns are considered problems:
The following patterns are not considered problems:
require-returns-check
Requires a return statement (or non-undefined
Promise resolve value) in
function bodies if a @returns
tag (without a void
or undefined
type)
is specified in the function's jsdoc comment.
Will also report @returns {void}
and @returns {undefined}
if exemptAsync
is set to false
no non-undefined
returned or resolved value is found.
Will also report if multiple @returns
tags are present.
Options
exemptAsync
- By default, functions which return a Promise
that are not
detected as resolving with a non-undefined
value and async
functions
(even ones that do not explicitly return a value, as these are returning a
Promise
implicitly) will be exempted from reporting by this rule.
If you wish to insist that only Promise
's which resolve to
non-undefined
values or async
functions with explicit return
's will
be exempted from reporting (i.e., that async
functions can be reported
if they lack an explicit (non-undefined
) return
when a @returns
is
present), you can set exemptAsync
to false
on the options object.reportMissingReturnForUndefinedTypes
- If true
and no return or
resolve value is found, this setting will even insist that reporting occur
with void
or undefined
(including as an indicated Promise
type).
Unlike require-returns
, with this option in the rule, one can
discourage the labeling of undefined
types. Defaults to false
.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression |
Tags | returns |
Aliases | return |
Options | exemptAsync , reportMissingReturnForUndefinedTypes |
Recommended | true |
The following patterns are considered problems:
function quux (foo) {
}
function quux (foo) {
}
const quux = () => {}
function quux () {
return foo;
}
const language = {
get name() {
this._name = name;
}
}
class Foo {
bar () {
}
}
function quux () {
}
function f () {
function g() {
return 'foo'
}
() => {
return 5
}
}
async function quux() {}
function quux() {
return new Promise((resolve, reject) => {})
}
function quux() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
});
})
}
async function foo() {
return new Promise(resolve => resolve());
}
async function foo() {
return new Promise(resolve => resolve());
}
function quux () {}
The following patterns are not considered problems:
function quux () {
return foo;
}
function quux () {
return foo;
}
function quux () {
return foo;
}
function quux () {
}
const quux = () => foo;
function quux () {}
function quux () {}
async function quux() {}
const quux = async function () {}
const quux = async () => {}
function quux () {
throw new Error('must be implemented by subclass!');
}
function quux () {
throw new Error('must be implemented by subclass!');
}
function quux () {
}
class Foo {
bar () {
}
}
class Foo {
bar () {
}
}
function quux () {
}
function quux () {
}
function quux () {
return undefined;
}
function quux () {
return;
}
function quux () {
return undefined;
}
function quux () {
return;
}
function quux () {
try {
return true;
} catch (err) {
}
return;
}
function quux () {
try {
} finally {
return true;
}
return;
}
function quux () {
try {
return;
} catch (err) {
}
return true;
}
function quux () {
try {
something();
} catch (err) {
return true;
}
return;
}
function quux () {
switch (true) {
case 'abc':
return true;
}
return;
}
function quux () {
switch (true) {
case 'abc':
return;
}
return true;
}
function quux () {
for (const i of abc) {
return true;
}
return;
}
function quux () {
for (const a in b) {
return true;
}
}
function quux () {
for (let i=0; i<n; i+=1) {
return true;
}
}
function quux () {
while(true) {
return true
}
}
function quux () {
do {
return true
}
while(true)
}
function quux () {
if (true) {
return;
}
return true;
}
function quux () {
if (true) {
return true;
}
}
function quux () {
var a = {};
with (a) {
return true;
}
}
function quux () {
if (true) {
return;
} else {
return true;
}
return;
}
async function quux() {
return 5;
}
async function quux() {
return 5;
}
function quux() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
});
})
}
async function foo() {
return new Promise(resolve => resolve());
}
function quux () {
return undefined;
}
function quux () {
return 'abc';
}
require-returns-description
Requires that the @returns
tag has a description
value. The error
will not be reported if the return value is void
or undefined
or if it is Promise<void>
or Promise<undefined>
.
Options
contexts
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to "any"
if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
expression, i.e., @callback
or @function
(or its aliases @func
or
@method
) (including those associated with an @interface
).
See the "AST and Selectors"
section of our README for more on the expected format.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | returns |
Aliases | return |
Recommended | true |
Options | contexts |
The following patterns are considered problems:
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function quux () {
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
require-returns-type
Requires that @returns
tag has type
value.
Options
contexts
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to "any"
if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
expression, i.e., @callback
or @function
(or its aliases @func
or
@method
) (including those associated with an @interface
).
See the "AST and Selectors"
section of our README for more on the expected format.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | returns |
Aliases | return |
Recommended | true |
Options | contexts |
The following patterns are considered problems:
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
function quux () {
}
The following patterns are not considered problems:
function quux () {
}
function quux () {
}
require-returns
Requires that returns are documented.
Will also report if multiple @returns
tags are present.
Options
checkConstructors
- A value indicating whether constructor
s should
be checked for @returns
tags. Defaults to false
.checkGetters
- Boolean to determine whether getter methods should
be checked for @returns
tags. Defaults to true
.exemptedBy
- Array of tags (e.g., ['type']
) whose presence on the
document block avoids the need for a @returns
. Defaults to an array
with inheritdoc
. If you set this array, it will overwrite the default,
so be sure to add back inheritdoc
if you wish its presence to cause
exemption of the rule.forceRequireReturn
- Set to true
to always insist on
@returns
documentation regardless of implicit or explicit return
's
in the function. May be desired to flag that a project is aware of an
undefined
/void
return. Defaults to false
.forceReturnsWithAsync
- By default async
functions that do not explicitly
return a value pass this rule as an async
function will always return a
Promise
, even if the Promise
resolves to void. You can force all
async
functions (including ones with an explicit Promise
but no
detected non-undefined
resolve
value) to require @return
documentation by setting forceReturnsWithAsync
to true
on the options
object. This may be useful for flagging that there has been consideration
of return type. Defaults to false
.contexts
- Set this to an array of strings representing the AST context
(or an object with context
and comment
properties) where you wish
the rule to be applied.
Overrides the default contexts (see below). Set to "any"
if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
expression, i.e., @callback
or @function
(or its aliases @func
or
@method
) (including those associated with an @interface
). This
rule will only apply on non-default contexts when there is such a tag
present and the forceRequireReturn
option is set or if the
forceReturnsWithAsync
option is set with a present @async
tag
(since we are not checking against the actual return
values in these
cases).
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | returns |
Aliases | return |
Recommended | true |
Options | checkConstructors , checkGetters , contexts , exemptedBy , forceRequireReturn , forceReturnsWithAsync |
Settings | overrideReplacesDocs , augmentsExtendsReplacesDocs , implementsReplacesDocs |
The following patterns are considered problems:
function quux (foo) {
return foo;
}
const foo = () => ({
bar: 'baz'
})
const foo = bar=>({ bar })
const foo = bar => bar.baz()
function quux (foo) {
return foo;
}
async function quux() {
}
const quux = async function () {}
const quux = async () => {}
async function quux () {}
function quux () {
}
function quux () {
}
const language = {
get name() {
return this._name;
}
}
async function quux () {
}
function quux (foo) {
return foo;
}
function quux () {
}
function quux (foo) {
return 'bar';
}
async function foo(a) {
return;
}
async function foo(a) {
return Promise.all(a);
}
class foo {
get bar() {
return 0;
}
}
class TestClass {
constructor() {
return new Map();
}
}
class TestClass {
get Test() {
return 0;
}
}
class quux {
quux () {
}
}
async function foo(a) {
return Promise.all(a);
}
function quux (foo) {
return new Promise(function (resolve, reject) {
resolve(foo);
});
}
function quux (foo) {
return new Promise(function (resolve, reject) {
setTimeout(() => {
resolve(true);
});
});
}
function quux (foo) {
return new Promise(function (resolve, reject) {
foo(resolve);
});
}
function quux () {
return new Promise((resolve, reject) => {
while(true) {
resolve(true);
}
});
}
function quux () {
return new Promise((resolve, reject) => {
do {
resolve(true);
}
while(true)
});
}
function quux () {
return new Promise((resolve, reject) => {
if (true) {
resolve(true);
}
return;
});
}
function quux () {
return new Promise((resolve, reject) => {
if (true) {
resolve(true);
}
});
}
function quux () {
var a = {};
return new Promise((resolve, reject) => {
with (a) {
resolve(true);
}
});
}
function quux () {
var a = {};
return new Promise((resolve, reject) => {
try {
resolve(true);
} catch (err) {}
});
}
function quux () {
var a = {};
return new Promise((resolve, reject) => {
try {
} catch (err) {
resolve(true);
}
});
}
function quux () {
var a = {};
return new Promise((resolve, reject) => {
try {
} catch (err) {
} finally {
resolve(true);
}
});
}
function quux () {
var a = {};
return new Promise((resolve, reject) => {
switch (a) {
case 'abc':
resolve(true);
}
});
}
function quux () {
return new Promise((resolve, reject) => {
if (true) {
resolve();
} else {
resolve(true);
}
});
}
function quux () {
return new Promise((resolve, reject) => {
for (let i = 0; i < 5 ; i++) {
resolve(true);
}
});
}
function quux () {
return new Promise((resolve, reject) => {
for (const i of obj) {
resolve(true);
}
});
}
function quux () {
return new Promise((resolve, reject) => {
for (const i in obj) {
resolve(true);
}
});
}
function quux () {
return new Promise((resolve, reject) => {
if (true) {
return;
} else {
resolve(true);
}
});
}
function quux () {
return new Promise((resolve, reject) => {
function a () {
resolve(true);
}
a();
});
}
function quux () {
return new Promise();
}
async function quux () {
return new Promise();
}
async function quux () {
return new Promise((resolve, reject) => {});
}
The following patterns are not considered problems:
function quux () {
return foo;
}
function quux () {
return foo;
}
function quux () {
}
function quux (bar) {
bar.filter(baz => {
return baz.corge();
})
}
function quux (bar) {
return bar.filter(baz => {
return baz.corge();
})
}
const quux = (bar) => bar.filter(({ corge }) => corge())
function quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
return true;
}
function quux (foo) {
return true;
}
function quux (foo) {
return foo;
}
function quux (foo) {
return true;
}
function quux (foo) {
}
function quux () {
return {a: foo};
}
const quux = () => ({a: foo});
const quux = () => {
return {a: foo}
};
function quux () {
}
const quux = () => {
}
function quux () {
}
const quux = () => {
}
function quux () {
}
const quux = () => {
}
class Foo {
constructor () {
}
}
const language = {
set name(name) {
this._name = name;
}
}
function quux () {
}
function quux () {
return undefined;
}
function quux () {
return undefined;
}
function quux () {
return;
}
function quux () {
}
function quux () {
return;
}
function quux (req, res , next) {
return;
}
async function quux () {
}
async function quux () {
}
async function quux () {}
const quux = async function () {}
const quux = async () => {}
class foo {
constructor () {
this.bar = true;
}
}
export default foo;
function quux () {
}
function quux () {
}
async function foo(a) {
return;
}
class foo {
get bar() {
return 0;
}
}
class foo {
get bar() {
return 0;
}
}
class foo {
get bar() {
return 0;
}
}
class TestClass {
constructor() { }
}
class TestClass {
constructor() {
return new Map();
}
}
class TestClass {
constructor() { }
}
class TestClass {
get Test() { }
}
class TestClass {
get Test() {
return 0;
}
}
class TestClass {
get Test() {
return 0;
}
}
function quux (foo) {
return new Promise(function (resolve, reject) {
resolve();
});
}
function quux (foo) {
return new Promise(function (resolve, reject) {
setTimeout(() => {
resolve();
});
});
}
function quux (foo) {
return new Promise(function (resolve, reject) {
foo();
});
}
function quux (foo) {
return new Promise(function (resolve, reject) {
abc((resolve) => {
resolve(true);
});
});
}
function quux (foo) {
return new Promise(function (resolve, reject) {
abc(function (resolve) {
resolve(true);
});
});
}
function quux () {
return new Promise((resolve, reject) => {
if (true) {
resolve();
}
});
return;
}
function quux () {
return new Promise();
}
async function foo() {
return new Promise(resolve => resolve());
}
require-throws
Requires that throw statements are documented.
Options
exemptedBy
- Array of tags (e.g., ['type']
) whose presence on the
document block avoids the need for a @throws
. Defaults to an array
with inheritdoc
. If you set this array, it will overwrite the default,
so be sure to add back inheritdoc
if you wish its presence to cause
exemption of the rule.contexts
- Set this to an array of strings representing the AST context
(or an object with context
and comment
properties) where you wish
the rule to be applied.
Overrides the default contexts (see below). Set to "any"
if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
expression, i.e., @callback
or @function
(or its aliases @func
or
@method
) (including those associated with an @interface
).
'jsdoc/require-throws': 'error',
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | throws |
Aliases | exception |
Recommended | true |
Options | contexts , exemptedBy |
Settings | overrideReplacesDocs , augmentsExtendsReplacesDocs , implementsReplacesDocs |
The following patterns are considered problems:
function quux (foo) {
throw new Error('err')
}
const quux = function (foo) {
throw new Error('err')
}
const quux = (foo) => {
throw new Error('err')
}
function quux (foo) {
while(true) {
throw new Error('err')
}
}
function quux (foo) {
do {
throw new Error('err')
} while(true)
}
function quux (foo) {
for(var i = 0; i <= 10; i++) {
throw new Error('err')
}
}
function quux (foo) {
for(num in [1,2,3]) {
throw new Error('err')
}
}
function quux (foo) {
for(const num of [1,2,3]) {
throw new Error('err')
}
}
function quux (foo) {
for(const index in [1,2,3]) {
throw new Error('err')
}
}
function quux (foo) {
with(foo) {
throw new Error('err')
}
}
function quux (foo) {
if (true) {
throw new Error('err')
}
}
function quux (foo) {
if (false) {
} else {
throw new Error('err')
}
}
function quux (foo) {
try {
throw new Error('err')
} catch(e) {
throw new Error(e.message)
}
}
function quux (foo) {
try {
} finally {
throw new Error(e.message)
}
}
function quux (foo) {
const a = 'b'
switch(a) {
case 'b':
throw new Error('err')
}
}
function quux () {
}
const directThrowAfterArrow = (b) => {
const a = () => {};
if (b) {
throw new Error('oops')
}
return a;
};
The following patterns are not considered problems:
function quux () {
throw new Error('err')
}
function quux (foo) {
try {
throw new Error('err')
} catch(e) {}
}
function quux (foo) {
throw new Error('err')
}
function quux (foo) {
throw new Error('err')
}
function quux (foo) {
}
function quux () {
throw new Error('err')
}
const itself = (n) => n;
const nested = () => () => {throw new Error('oops');};
require-yields
Requires that yields are documented.
Will also report if multiple @yields
tags are present.
See the next
, forceRequireNext
, and nextWithGeneratorTag
options for an
option to expect a non-standard @next
tag.
Options
exemptedBy
- Array of tags (e.g., ['type']
) whose presence on the
document block avoids the need for a @yields
. Defaults to an array
with inheritdoc
. If you set this array, it will overwrite the default,
so be sure to add back inheritdoc
if you wish its presence to cause
exemption of the rule.forceRequireYields
- Set to true
to always insist on
@yields
documentation for generators even if there are only
expressionless yield
statements in the function. May be desired to flag
that a project is aware of an undefined
/void
yield. Defaults to
false
.contexts
- Set this to an array of strings representing the AST context
(or an object with context
and comment
properties) where you wish
the rule to be applied.
Overrides the default contexts (see below). Set to "any"
if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
expression, i.e., @callback
or @function
(or its aliases @func
or
@method
) (including those associated with an @interface
). This
rule will only apply on non-default contexts when there is such a tag
present and the forceRequireYields
option is set or if the
withGeneratorTag
option is set with a present @generator
tag
(since we are not checking against the actual yield
values in these
cases).withGeneratorTag
- If a @generator
tag is present on a block, require
@yields
/@yield
. Defaults to true
. See contexts
to any
if you want
to catch @generator
with @callback
or such not attached to a function.next
- If true
, this option will insist that any use of a yield
return
value (e.g., const rv = yield;
or const rv = yield value;
) has a
(non-standard) @next
tag (in addition to any @yields
tag) so as to be
able to document the type expected to be supplied into the iterator
(the Generator
iterator that is returned by the call to the generator
function) to the iterator (e.g., it.next(value)
). The tag will not be
expected if the generator function body merely has plain yield;
or
yield value;
statements without returning the values. Defaults to
false
.forceRequireNext
- Set to true
to always insist on
@next
documentation even if there are no yield
statements in the
function or none return values. May be desired to flag that a project is
aware of the expected yield return being undefined
. Defaults to false
.nextWithGeneratorTag
- If a @generator
tag is present on a block, require
(non-standard ) @next
(see next
option). This will require using void
or undefined
in cases where generators do not use the next()
-supplied
incoming yield
-returned value. Defaults to false
. See contexts
to
any
if you want to catch @generator
with @callback
or such not
attached to a function.
| |
---|
Context | Generator functions (FunctionDeclaration , FunctionExpression ; others when contexts option enabled) |
Tags | yields |
Aliases | yield |
Recommended | true |
Options | contexts , exemptedBy , withGeneratorTag , nextWithGeneratorTag , forceRequireYields , next |
Settings | overrideReplacesDocs , augmentsExtendsReplacesDocs , implementsReplacesDocs |
The following patterns are considered problems:
function * quux (foo) {
yield foo;
}
function * quux (foo) {
const retVal = yield foo;
}
function * quux (foo) {
const retVal = yield;
}
function * quux () {
}
function * quux () {
yield;
}
function * quux (foo) {
const a = yield foo;
}
function * quux (foo) {
yield foo;
}
function * quux (foo) {
const val = yield foo;
}
function * quux () {
const ret = yield 5;
}
function * quux() {
yield 5;
}
function * quux() {
yield;
}
const quux = async function * () {
yield;
}
async function * quux () {
yield;
}
function * quux () {
yield;
}
function * quux (foo) {
return foo;
}
function * quux () {
}
function * quux (foo) {
yield 'bar';
}
async function * foo(a) {
return;
}
async function * foo(a) {
yield Promise.all(a);
}
class quux {
* quux () {
yield;
}
}
async function * foo(a) {
yield Promise.all(a);
}
function * quux () {
if (true) {
yield;
}
yield true;
}
function * quux () {
try {
yield true;
} catch (err) {
}
yield;
}
function * quux () {
try {
} finally {
yield true;
}
yield;
}
function * quux () {
try {
yield;
} catch (err) {
}
yield true;
}
function * quux () {
try {
something();
} catch (err) {
yield true;
}
yield;
}
function * quux () {
switch (true) {
case 'abc':
yield true;
}
yield;
}
function * quux () {
switch (true) {
case 'abc':
yield;
}
yield true;
}
function * quux () {
for (const i of abc) {
yield true;
}
yield;
}
function * quux () {
for (const a in b) {
yield true;
}
}
function * quux () {
for (let i=0; i<n; i+=1) {
yield true;
}
}
function * quux () {
while(true) {
yield true
}
}
function * quux () {
do {
yield true
}
while(true)
}
function * quux () {
if (true) {
yield;
}
yield true;
}
function * quux () {
if (true) {
yield true;
}
}
function * quux () {
var a = {};
with (a) {
yield true;
}
}
function * quux () {
if (true) {
yield;
} else {
yield true;
}
yield;
}
The following patterns are not considered problems:
function * quux () {
yield foo;
}
function * quux () {
yield foo;
}
function * quux () {
}
function * quux () {
yield;
}
function quux (bar) {
bar.doSomething(function * (baz) {
yield baz.corge();
})
}
function * quux (bar) {
yield bar.doSomething(function * (baz) {
yield baz.corge();
})
}
function * quux (foo) {
}
function * quux (foo) {
}
function * quux (foo) {
}
function * quux (foo) {
yield;
}
function * quux (foo) {
yield foo;
}
function * quux (foo) {
yield foo;
}
function * quux (foo) {
}
function * quux () {
yield {a: foo};
}
function * quux () {
}
function * quux () {
}
function * quux () {
}
function quux () {
}
function * quux () {
}
function * quux () {
yield undefined;
}
function * quux () {
yield undefined;
}
function * quux () {
yield;
}
function * quux () {
}
function * quux () {
yield;
}
function * quux () {
yield 5;
}
async function * quux () {
}
async function * quux () {}
const quux = async function * () {}
function * quux () {
yield;
}
async function * foo (a) {
yield;
}
function * quux (foo) {
const a = yield foo;
}
function * quux (foo) {
let a = yield;
}
function * quux (foo) {
const a = yield foo;
}
function quux () {}
function * quux () {
yield;
}
function * quux (foo) {
const a = function * bar () {
yield foo;
}
}
require-yields-check
Ensures that if a @yields
is present that a yield
(or yield
with a
value) is present in the function body (or that if a @next
is present that
there is a yield
with a return value present).
Please also note that JavaScript does allow generators not to have yield
(e.g., with just a return or even no explicit return), but if you want to
enforce that all generators (except wholly empty ones) have a yield
in the
function body, you can use the ESLint
require-yield
rule. In
conjunction with this, you can also use the checkGeneratorsOnly
option
as an optimization so that this rule won't need to do its own checking within
function bodies.
Will also report if multiple @yields
tags are present.
Options
checkGeneratorsOnly
- Avoids checking the function body and merely insists
that all generators have @yields
. This can be an optimization with the
ESLint require-yield
rule, as that rule already ensures a yield
is
present in generators, albeit assuming the generator is not empty).
Defaults to false
.next
- If true
, this option will insist that any use of a (non-standard)
@next
tag (in addition to any @yields
tag) will be matched by a yield
which uses a return value in the body of the generator (e.g.,
const rv = yield;
or const rv = yield value;
). This (non-standard)
tag is intended to be used to indicate a type and/or description of
the value expected to be supplied by the user when supplied to the iterator
by its next
method, as with it.next(value)
(with the iterator being
the Generator
iterator that is returned by the call to the generator
function). This option will report an error if the generator function body
merely has plain yield;
or yield value;
statements without returning
the values. Defaults to false
.
| |
---|
Context | ArrowFunctionExpression , FunctionDeclaration , FunctionExpression |
Tags | yields |
Aliases | yield |
Recommended | true |
Options | checkGeneratorsOnly |
The following patterns are considered problems: | |
function * quux (foo) {
}
function quux (foo) {
}
function quux (foo) {
}
function * quux (foo) {
}
function * quux (foo) {
yield;
}
function * quux (foo) {
yield 5;
}
function * quux (foo) {
}
function * quux (foo) {
yield;
}
function * quux () {
yield foo;
}
class Foo {
* bar () {
}
}
function * quux () {
}
function * quux () {
}
function * f () {
function * g() {
yield 'foo'
}
}
async function * quux() {}
const quux = async function * () {}
The following patterns are not considered problems:
function * quux () {
yield foo;
}
function * quux () {
yield foo;
}
function * quux () {
yield foo;
}
function * quux () {
}
function * quux () {}
function quux () {}
function * quux () {
throw new Error('must be implemented by subclass!');
}
function * quux () {
throw new Error('must be implemented by subclass!');
}
function * quux () {
}
class Foo {
* bar () {
}
}
class Foo {
* bar () {
}
}
function * quux () {
}
function * quux () {
}
function * quux () {
yield undefined;
}
function * quux () {
yield;
}
function * quux () {
yield undefined;
}
function * quux () {
yield;
}
function * quux () {
try {
yield true;
} catch (err) {
}
yield;
}
function * quux () {
try {
} finally {
yield true;
}
yield;
}
function * quux () {
try {
yield;
} catch (err) {
}
yield true;
}
function * quux () {
try {
something();
} catch (err) {
yield true;
}
yield;
}
function * quux () {
switch (true) {
case 'abc':
yield true;
}
yield;
}
function * quux () {
switch (true) {
case 'abc':
yield;
}
yield true;
}
function * quux () {
for (const i of abc) {
yield true;
}
yield;
}
function * quux () {
for (const a in b) {
yield true;
}
}
function * quux () {
for (let i=0; i<n; i+=1) {
yield true;
}
}
function * quux () {
while(true) {
yield true
}
}
function * quux () {
do {
yield true
}
while(true)
}
function * quux () {
if (true) {
yield;
}
yield true;
}
function * quux () {
if (true) {
yield true;
}
}
function * quux () {
var a = {};
with (a) {
yield true;
}
}
function * quux () {
if (true) {
yield;
} else {
yield true;
}
yield;
}
function * quux (foo) {
}
function * quux (foo) {
const a = yield;
}
function * quux (foo) {
const a = yield 5;
}
tag-lines
Enforces lines (or no lines) between tags.
Options
The first option is a single string set to "always", "never", or "any"
(defaults to "never").
"any" is only useful with tags
(allowing non-enforcement of lines except
for particular tags).
The second option is an object with the following optional properties.
count
(defaults to 1)
Use with "always" to indicate the number of lines to require be present.
noEndLines
(defaults to false
)
Use with "always" to indicate the normal lines to be added after tags should
not be added after the final tag.
tags
(default to empty object)
Overrides the default behavior depending on specific tags.
An object whose keys are tag names and whose values are objects with the
following keys:
lines
- Set to always
or never
to override.count
- Overrides main count
(for "always")
| |
---|
Context | everywhere |
Tags | Any |
Recommended | true |
Settings | N/A |
Options | (a string matching "always" or "never" and optional object with count and noEndLines ) |
The following patterns are considered problems:
The following patterns are not considered problems:
valid-types
Requires all types to be valid JSDoc, Closure, or TypeScript compiler types
without syntax errors. Note that what determines a valid type is handled by
our type parsing engine, jsdoctypeparser,
using settings.jsdoc.mode
to
determine whether to use jsdoctypeparser's "permissive" mode or the stricter
"jsdoc", "typescript", "closure" modes.
The following tags have their "type" portions (the segment within brackets)
checked (though those portions may sometimes be confined to namepaths,
e.g., @modifies
):
- Tags with required types:
@type
, @implements
- Tags with required types in Closure or TypeScript:
@this
,
@define
(Closure only) - Tags with optional types:
@enum
, @member
(@var
), @typedef
,
@augments
(or @extends
), @class
(or @constructor
), @constant
(or @const
), @module
(module paths are not planned for TypeScript),
@namespace
, @throws
, @exception
, @yields
(or @yield
),
@modifies
(undocumented jsdoc); @param
(@arg
, @argument
),
@property
(@prop
), and @returns
(@return
) also fall into this
category, but while this rule will check their type validity, we leave
the requiring of the type portion to the rules require-param-type
,
require-property-type
, and require-returns-type
, respectively. - Tags with types that are available optionally in Closure:
@export
,
@package
, @private
, @protected
, @public
, @static
;
@template
(TypeScript also) - Tags with optional types that may take free text instead:
@throws
The following tags have their name/namepath portion (the non-whitespace
text after the tag name) checked:
- Name(path)-defining tags requiring namepath:
@event
, @callback
,
@external
, @host
, @name
, @typedef
, and @template
(TypeScript/Closure only); @param
(@arg
, @argument
) and @property
(@prop
) also fall into this category, but while this rule will check
their namepath validity, we leave the requiring of the name portion
to the rules require-param-name
and require-property-name
,
respectively. - Name(path)-defining tags (which may have value without namepath or their
namepath can be expressed elsewhere on the block):
@class
, @constructor
, @constant
, @const
, @function
, @func
,
@method
, @interface
(TypeScript tag only), @member
, @var
,
@mixin
, @namespace
, @module
(module paths are not planned for
TypeScript) - Name(path)-pointing tags requiring namepath:
@alias
, @augments
,
@extends
, @lends
, @memberof
, @memberof!
, @mixes
, @this
(jsdoc only) - Name(path)-pointing tags (which may have value without namepath or their
namepath can be expressed elsewhere on the block):
@listens
, @fires
,
@emits
. - Name(path)-pointing tags which may have free text or a namepath:
@see
- Name(path)-pointing tags (multiple names in one):
@borrows
...with the following applying to the above sets:
- Expect tags in set 1-4 to have a valid namepath if present
- Prevent sets 2 and 4 from being empty by setting
allowEmptyNamepaths
to
false
as these tags might have some indicative value without a path
or may allow a name expressed elsewhere on the block (but sets 1 and 3 will
always fail if empty) - For the special case of set 6, i.e.,
@borrows <that namepath> as <this namepath>
,
check that both namepaths are present and valid and ensure there is an as
between them. In the case of <this namepath>
, it can be preceded by
one of the name path operators, #
, .
, or ~
. - For the special case of
@memberof
and @memberof!
(part of set 3), as
per the specification, they also
allow #
, .
, or ~
at the end (which is not allowed at the end of
normal paths).
If you define your own tags, settings.jsdoc.structuredTags
will allow
these custom tags to be checked, with the name portion of tags checked for
valid namepaths (based on the tag's name
value), their type portions checked
for valid types (based on the tag's type
value), and either portion checked
for presence (based on false
name
or type
values or their required
value). See the setting for more details.
Options
allowEmptyNamepaths
(default: true) - Set to false
to bulk disallow
empty name paths with namepath groups 2 and 4 (these might often be
expected to have an accompanying name path, though they have some
indicative value without one; these may also allow names to be defined
in another manner elsewhere in the block); you can use
settings.jsdoc.structuredTags
with the required
key set to "name" if you
wish to require name paths on a tag-by-tag basis.
| |
---|
Context | everywhere |
Tags | For name only unless otherwise stated: alias , augments , borrows , callback , class (for name and type), constant (for name and type), enum (for type), event , external , fires , function , implements (for type), interface , lends , listens , member (for name and type), memberof , memberof! , mixes , mixin , modifies , module (for name and type), name , namespace (for name and type), param (for name and type), property (for name and type), returns (for type), see (optionally for name), this , throws (for type), type (for type), typedef (for name and type), yields (for type) |
Aliases | extends , constructor , const , host , emits , func , method , var , arg , argument , prop , return , exception , yield |
Closure-only | For type only: package , private , protected , public , static |
Recommended | true |
Options | allowEmptyNamepaths |
Settings | mode , structuredTags |
The following patterns are considered problems:
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
const FOO = 'foo';
class Bar {};
let foo;
function quux (foo, bar, baz) {}
function quux () {}
function quux () {}
function quux () {}
let foo;
function foo(bar) {}
function quux () {}
function quux () {}
function quux () {}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
parseArray = function(parser) {
return function(array) {
return array.map(parser);
};
};
parseArray = function(parser) {
return function(array) {
return array.map(parser);
};
};
parseArray = function(parser) {
return function(array) {
return array.map(parser);
};
};
The following patterns are not considered problems:
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
function quux() {
}
const FOO = 'foo';
const FOO = 'foo';
class Bar {};
class Bar {};
class Bar {};
let UserDefinedGCCType;
function quux (foo, bar, baz) {}
function quux () {}
function quux () {}
function quux () {}
function quux () {}
function foo(bar) {}
function foo(bar) {}
function foo(bar) {}
function foo(bar) {}
function quux () {}
function quux () {}
function quux() {
}
function quux() {
}
parseArray = function(parser) {
return function(array) {
return array.map(parser);
};
};
parseArray = function(parser) {
return function(array) {
return array.map(parser);
};
};
function seriousalize(key, object) {
}
function f() {}
type ComplicatedType<T, U, V, W, X> = never